New (Regex constructor): Difference between revisions
Jump to navigation
Jump to search
(Automatically generated page update) |
|||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
{{Template:Regex:New subtitle}} | {{Template:Regex:New subtitle}} | ||
This | This constructor creates a new instance of the <var>Regex</var> class. | ||
==Syntax== | ==Syntax== | ||
{{Template:Regex:New syntax}} | {{Template:Regex:New syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%outRegex</th><td> | <tr><th>%outRegex</th><td>The new <var>Regex</var> object.</td></tr> | ||
<tr><th nowrap="true"><var>[%(Regex):]</var></th> | <tr><th nowrap="true"><var>[%(Regex):]</var></th> | ||
<td>The optional class name in parentheses denotes a <var>[[Notation conventions for methods#Constructors|Constructor]] | <td>The optional class name in parentheses denotes a <var>[[Notation conventions for methods#Constructors|Constructor]]</var>.</td></tr> | ||
<tr><th>regex</th> | <tr><th>regex</th> | ||
<td>string</td></tr> | <td>The regular expression string to be compiled to create the <var>Regex</var> object.</td></tr> | ||
<tr><th><var> | <tr><th><var>replace</var></th> | ||
<td>string< | <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. | ||
<tr><th><var> | <p>See the [[Replace (Regex function)|Replace function]] for more information on the interpretation of the replacement string.</p> | ||
<td>string | </td></tr> | ||
<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></tr> | |||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>If <var>regex</var> 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 <var>Regex</var> object. The same is true of the <var>replace</var> string if one is present.</li> | |||
<li><var>regex</var> and <var>replace</var> (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.</li> | |||
<li>If <var>regex</var> is a <var>Unicode</var> value, the <var>Regex</var> object will do Unicode matching.</li> | |||
</ul> | |||
==Examples== | ==Examples== | ||
The following example creates a <var>Regex</var> object that does a case-independent search for the letters "foobar" with arbitrary characters between them: | |||
<p class="code">%regex is object regex | |||
... | |||
%regex = new("f.*o.*o.*b.*a.*r", options="i") | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:Regex:New footer}} | {{Template:Regex:New footer}} | ||
[[Category:Regular expression processing]] |
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
%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")