Subset (Regex function): Difference between revisions

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


This page is [[under construction]].
This function searches a [[Stringlist_class|Stringlist]] for any items that match the regular expression in the <var>Regex</var> object and places any matching items on a new <var>Stringlist</var>. It provides similary functionality to [[RegexSubset (Stringlist function)|RegexSubset]].
==Syntax==
==Syntax==
{{Template:Regex:Subset syntax}}
{{Template:Regex:Subset syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%subsetList</th><td>Object</td></tr>
<tr><th>%subsetList</th><td>A new <var>Stringlist</var> containing a copy of every item in <var>sl</var> that matches the regular expression in the <var>Regex</var> object.</td></tr>
<tr><th>regex</th>
<tr><th>regex</th>
<td><var>Regex</var> object</td></tr>
<td>The <var>Regex</var> object</td></tr>
<tr><th>stringlist</th>
<tr><th>sl</th>
<td><var>Stringlist</var> object</td></tr>
<td>The <var>Stringlist</var> whose items are matched against the regular expression in the <var>Regex</var> object.</td></tr>
<tr><th><var>StartCol</var></th>
<tr><th><var>StartCol</var></th>
<td>number<br/>The default value of this argument is [[??]].</td></tr>
<td>The starting column number (position in stringlist items) to which to limit the match. The default value of this argument is 1. This value must be greater than or equal to 1 and less than or equal to 6124.</td></tr>
<tr><th><var>EndCol</var></th>
<tr><th><var>EndCol</var></th>
<td>number<br/>The default value of this argument is [[??]].</td></tr>
<td>The ending column number (position in stringlist items) to which to limit the match. There is no default value of this argument so essentially matching is done to the end of each item. This value must be greater than or equal to <var>StartCol</var> and less than or equal to 6124.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>If the regular expression specified in the constructor call was Unicode, this method causes request cancellation. To test if a <var>Regex</var> object was created with a Unicode regular expression check the [[IsUnicode (Regex property)|IsUnicode property]].</li>
<li>If <var>EndCol</var> was not specified and a <var>Stringlist</var> item longer than 6124 bytes is encountered, the request is canceled.</li>
</ul>
==Examples==
==Examples==
The following displays the subset of a <var>Stringlist</var> whose items contain a <code>"q"</code> not followed by a <code>"u"</code>:
<p class="code">b                                                                       
                                                                         
%regex  is object regex                                                 
%list is object stringlist                                               
                                                                         
%list = list("Cueball", "Iraqi", "Questioning", "Shaq", "Aqua", "Quietly")
%regex = new("q(?!u)", options="i")                                     
%regex:subset(%list):print                                               
                                                                         
end                                                                     
</p>
The above displays:
<p class="code">Iraqi
Shaq 
</p>
Note that the <code>"(?!u)"</code> in the regular expression is an example of [https://www.regular-expressions.info/lookaround.html negative lookahead].
==See also==
==See also==
{{Template:Regex:Subset footer}}
{{Template:Regex:Subset footer}}
[[Category:Regular expression processing]]

Latest revision as of 21:05, 24 March 2022

Create subset of Stringlist that matches a regex (Regex class)


This function searches a Stringlist for any items that match the regular expression in the Regex object and places any matching items on a new Stringlist. It provides similary functionality to RegexSubset.

Syntax

%subsetList = regex:Subset( sl, [StartCol= number], [EndCol= number])

Syntax terms

%subsetListA new Stringlist containing a copy of every item in sl that matches the regular expression in the Regex object.
regex The Regex object
sl The Stringlist whose items are matched against the regular expression in the Regex object.
StartCol The starting column number (position in stringlist items) to which to limit the match. The default value of this argument is 1. This value must be greater than or equal to 1 and less than or equal to 6124.
EndCol The ending column number (position in stringlist items) to which to limit the match. There is no default value of this argument so essentially matching is done to the end of each item. This value must be greater than or equal to StartCol and less than or equal to 6124.

Usage notes

  • If the regular expression specified in the constructor call was Unicode, this method causes request cancellation. To test if a Regex object was created with a Unicode regular expression check the IsUnicode property.
  • If EndCol was not specified and a Stringlist item longer than 6124 bytes is encountered, the request is canceled.

Examples

The following displays the subset of a Stringlist whose items contain a "q" not followed by a "u":

b %regex is object regex %list is object stringlist %list = list("Cueball", "Iraqi", "Questioning", "Shaq", "Aqua", "Quietly") %regex = new("q(?!u)", options="i") %regex:subset(%list):print end

The above displays:

Iraqi Shaq

Note that the "(?!u)" in the regular expression is an example of negative lookahead.

See also