New (Regex constructor): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
No edit summary
Line 1: Line 1:
{{Template:Regex:New subtitle}}
{{Template:Regex:New subtitle}}


This page is [[under construction]].
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>regex</td></tr>
<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]]</var>. See [[#Usage notes|"Usage notes"]], below, for more information about invoking a <var>Constructor</var>.</td></tr>
<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>Replace</var></th>
<tr><th><var>replace</var></th>
<td>string<br/>The default value of this argument is [[??]].</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.</td></tr>
<tr><th><var>Options</var></th>
<tr><th><var>options</var></th>
<td>string<br/>The default value of this argument is [[??]].</td></tr>
<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]]

Revision as of 03:20, 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.
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