New (Regex constructor)
Create new Regex instance (Regex class)
This constructor creates a new instance of the Regex class.
Syntax
%regex = [%(Regex):]New( regex, [Replace= string], [Options= string]) Throws InvalidRegex
Syntax terms
%outRegex | The new Regex object. |
---|---|
[%(Regex):] | The optional class name in parentheses denotes a Constructor. |
regex | The regular expression string to be compiled to create the Regex object. |
replace | A replacement string to be compiled into the Regex object. If specified, this string is used by the Replace function if no replacement string is specified for a call. If replace is not specified, a replacement string must be specified for any Replace using the Regex object.
See the Replace function for more information on the interpretation of the replacement string. |
options | A string of single letter options, which may be specified in uppercase or lowercase, in any combination, and blank separated or not. For more information about these options, see Common regex options. |
Usage notes
- If regex is a literal string, it is compiled at the time the containing SOUL program is compiled and the compiled regular expression is simply loaded into the Regex object. The same is true of the replace string if one is present.
- regex and replace (including the source strings) must compile to a length less than or equal to the value of the REGXSTBL parameter. If it does not, te request is canceled.
- If regex is a Unicode value, the Regex object will do Unicode matching.
Examples
The following example creates a Regex object that does a case-independent search for the letters "foobar" with arbitrary characters between them:
%regex is object regex ... %regex = new("f.*o.*o.*b.*a.*r", options="i")