RegexSubset (Stringlist function): Difference between revisions
m (syntax diagram, tags and links) |
m (match syntax diagram case to template) |
||
Line 12: | Line 12: | ||
<tr><th>regex</th> | <tr><th>regex</th> | ||
<td>A string that is interpreted as a regular expression and is applied to the <var class="term">sl</var> method <var>Stringlist</var> items to determine whether the <var class="term">regex</var> finds a match.</td></tr> | <td>A string that is interpreted as a regular expression and is applied to the <var class="term">sl</var> method <var>Stringlist</var> items to determine whether the <var class="term">regex</var> finds a match.</td></tr> | ||
<tr><th><b> | <tr><th><b>Options</b></th> | ||
<td>The <var class="term"> | <td>The <var class="term">Options</var> argument (name required) is an optional string of options. The options are single letters, which may be specified in uppercase or lowercase, in any combination, and separated by blanks or not separated. For more information about these options, see [[Regex processing]]. | ||
<table class="syntaxNested"> | <table class="syntaxNested"> | ||
<tr><th>I</th> | <tr><th>I</th> | ||
Line 25: | Line 25: | ||
</table> | </table> | ||
</td></tr> | </td></tr> | ||
<tr><th><b> | <tr><th><b>Status</b></th> | ||
<td>The <var class="term"> | <td>The <var class="term">Status</var> argument (name required) is optional; if specified, it is set to an integer code. These values are possible: | ||
<table class="syntaxNested"> | <table class="syntaxNested"> | ||
<tr><th><i>n</i></th> | <tr><th><i>n</i></th> | ||
Line 33: | Line 33: | ||
<td>No match: no items in <var class="term">sl</var> were matched by <var class="term">regex</var>.</td></tr> | <td>No match: no items in <var class="term">sl</var> were matched by <var class="term">regex</var>.</td></tr> | ||
<tr><th>-2</th> | <tr><th>-2</th> | ||
<td>Invalid <var class="term"> | <td>Invalid <var class="term">StartCol</var> or <var class="term">EndCol</var> argument value.</td></tr> | ||
<tr><th>-1<i>nnn</i></th> | <tr><th>-1<i>nnn</i></th> | ||
<td>The pattern in <var class="term">regex</var> is invalid. <i>nnn</i> (the absolute value of the return minus 1000) gives the 1-based position of the character being scanned when the error was discovered. The value for an error occurring at end-of-string is the length of the string + 1. Prior to <var class="product">Sirius Mods</var> Version 7.0, an invalid <var class="term">regex</var> results in a <var class="term">Status</var> value of <code>-1</code>.</td></tr> | <td>The pattern in <var class="term">regex</var> is invalid. <i>nnn</i> (the absolute value of the return minus 1000) gives the 1-based position of the character being scanned when the error was discovered. The value for an error occurring at end-of-string is the length of the string + 1. Prior to <var class="product">Sirius Mods</var> Version 7.0, an invalid <var class="term">regex</var> results in a <var class="term">Status</var> value of <code>-1</code>.</td></tr> | ||
</table> | </table> | ||
If you omit this argument and a negative Status value is to be returned, the run is cancelled.</td></tr> | If you omit this argument and a negative Status value is to be returned, the run is cancelled.</td></tr> | ||
<tr><th><b> | <tr><th><b>StartCol</b></th> | ||
<td>The <var class="term"> | <td>The <var class="term">StartCol</var> argument (name required) is an optional <var class="term">number</var> that specifies the starting column of the range of columns in which the matched string must be located. If specified, <var class="term">number</var> must be greater than or equal to 1 and less than or equal to the <var class="term">EndCol</var> argument value. If the argument is omitted, its default value is 1. If you specify a <var class="term">number</var> value that is greater than the length of a particular <var class="term">sl</var> item, the <var class="term">regex</var> is matched against the empty string for that item.</td> | ||
<tr><th><b> | <tr><th><b>EndCol</b></th> | ||
<td>The <var class="term"> | <td>The <var class="term">EndCol</var> argument (name required) is an optional <var class="term">number</var> that specifies the ending column of the range of columns in which the matched string must be located. If specified, <var class="term">number</var> must be greater than or equal to 1, and greater than or equal to the <var class="term">StartCol</var> argument value, and less than or equal to the lesser of 6124 or the length of <var class="term">sl</var> item. If the <var class="term">EndCol</var> argument is omitted, its default value is 6124.<p>If the <var class="term">EndCol</var> argument is omitted and a <var class="term">sl</var> item exceeds 6124 bytes, the request is cancelled.</p></td> | ||
</table> | </table> | ||
Revision as of 09:21, 29 January 2011
Create subset of Stringlist that matches a regex (Stringlist class)
This method returns a Stringlist that is a subset of the method Stringlist. The subset contains copies of all the items in the method Stringlist that are matched by a specified regex. Information about the regular expression matching rules observed is provided in Regex processing.
RegexSubset accepts one required and four optional arguments, and it returns a Stringlist.
Syntax
%subsetList = sl:RegexSubset( regex, [Options= string], [Status= %output], - [StartCol= number], [EndCol= number]) Throws InvalidRegex
Syntax terms
%subsetList | A Stringlist that contains the sl items matched by regex. | ||||||||
---|---|---|---|---|---|---|---|---|---|
sl | A Stringlist object. | ||||||||
regex | A string that is interpreted as a regular expression and is applied to the sl method Stringlist items to determine whether the regex finds a match. | ||||||||
Options | The Options argument (name required) is an optional string of options. The options are single letters, which may be specified in uppercase or lowercase, in any combination, and separated by blanks or not separated. For more information about these options, see Regex processing.
| ||||||||
Status | The Status argument (name required) is optional; if specified, it is set to an integer code. These values are possible:
| ||||||||
StartCol | The StartCol argument (name required) is an optional number that specifies the starting column of the range of columns in which the matched string must be located. If specified, number must be greater than or equal to 1 and less than or equal to the EndCol argument value. If the argument is omitted, its default value is 1. If you specify a number value that is greater than the length of a particular sl item, the regex is matched against the empty string for that item. | ||||||||
EndCol | The EndCol argument (name required) is an optional number that specifies the ending column of the range of columns in which the matched string must be located. If specified, number must be greater than or equal to 1, and greater than or equal to the StartCol argument value, and less than or equal to the lesser of 6124 or the length of sl item. If the EndCol argument is omitted, its default value is 6124. If the EndCol argument is omitted and a sl item exceeds 6124 bytes, the request is cancelled. |
Usage notes
- All errors in RegexSubset, including invalid argument(s) result in request cancellation.
- It is strongly recommended that you protect your environment from regex processing demands on PDL and STBL space by setting, say,
UTABLE LPDLST 3000
andUTABLE LSTBL 9000
. For further discussion of this, see User Language coding considerations. - The regex matching is limited to the first 6124 bytes of each item, but a matched item is copied in its entirety to the output subset.
- Prior to copying matched items to %subsetList, any preexisting contents of that Stringlist are deleted.
- For information about additional methods and $functions that support regular expressions, see Regex processing.
- RegexSubset is available as of Sirius Mods Version 6.9.
Examples
- In the following code fragment, RegexSubset is applied to the method Stringlist
%sl
to find the%sl
items that are matched by the regex%\([a-z]*\)
. The regex is designed to find items that contain shared methods whose class names contain only upper and lowercase letters.... %sl = new text to %sl b %doc is object xmlDoc %(daemon):getInputObject(%doc) %doc:selectSingleNode('/outer/inner'):addAttribute('foo','bar') %(daemon):returnObject(%doc) end end text %regex = '%\([a-z]*\)' %opt='i' %sl2 = %sl:RegexSubset (%regex, Options=%opt, Status=%st) If (%st EQ 0) then Print 'Status from RegexSubset is ' %st Else Print %regex ' matches the following items:' End If For %i from 1 to %sl2:Count Print 'Matching item ' %i ' is: ' %sl2:Item(%i) End For ...
This code would print the following:
%\([a-z]*\) matches the following items: Matching item 1 is: %(daemon):getInputObject(%doc) Matching item 2 is: %(daemon):returnObject(%doc)