New (Regex constructor): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
 
Line 12: Line 12:
<td>The regular expression string to be compiled to create the <var>Regex</var> object.</td></tr>
<td>The regular expression string to be compiled to create the <var>Regex</var> object.</td></tr>
<tr><th><var>replace</var></th>
<tr><th><var>replace</var></th>
<td>A replacement string to be compiled into the <var>Regex</var> object. If specified, this string is used by the [[Replace (Regex function)|Replace function]] if no replacement string is specified for a call. If <var>replace</var> is not specified, a replacement string must be specified for any <var>Replace</var> using the <var>Regex</var> object.</td></tr>
<td>A replacement string to be compiled into the <var>Regex</var> object. If specified, this string is used by the [[Replace (Regex function)|Replace function]] if no replacement string is specified for a call. If <var>replace</var> is not specified, a replacement string must be specified for any <var>Replace</var> using the <var>Regex</var> object.
<p>See the [[Replace (Regex function)|Replace function]] for more information on the interpretation of the replacement string.</p>
</td></tr>
<tr><th><var>options</var></th>
<tr><th><var>options</var></th>
<td>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 [[Regex_processing#Common_regex_options|Common regex options]].
<td>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 [[Regex_processing#Common_regex_options|Common regex options]].
</td></tr>
</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>

Latest revision as of 19:58, 23 March 2022

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

%outRegexThe 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")

See also