Method RegEx():split() Foundation

Splits a string using the pattern as delimiter.

Syntax
:split( <cSubject>, [<nLimit>], [<lKeepEmpty>] ) --> aFragments
Parameters
<cSubject>
The subject string to split.
<nLimit>
The maximum number of fragments to return. This defaults to 10000.
<lKeepEmpty>
Specifies whether empty fragments are included in the result. Defaults to .T. (true) which means empty fragments are returned in the result.
Return

An array with the string fragments.

Description

Divides the subject string into fragments using matches of the pattern as separators. Similar to tokenizing but with regular expression patterns instead of simple delimiters.

Split

oRegEx := RegEx():create("[,;]+")  // Split by comma or semicolon 
aFields := oRegEx:split("apple,banana;;cherry") 
? aFields  // {"apple", "banana", "cherry"} 
oRegEx:destroy() 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.