RegexLocate and RegexLocateUp (Stringlist functions): Difference between revisions
m (syntax table) |
m (syntax table) |
||
Line 47: | Line 47: | ||
<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 the argument is specified, its value 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 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> | <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 the argument is specified, its value 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 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> | ||
<tr><th><b>endCol</b></th> | <tr><th><b>endCol</b></th> | ||
<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 the argument is specified, its value must be greater than or equal to 1, greater than or equal to the <var class="term">startCol</var> argument value, and less than or equal to 6124. If the <var class="term">endCol</var> argument is omitted, its default value is 6124.< | <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 the argument is specified, its value must be greater than or equal to 1, greater than or equal to the <var class="term">startCol</var> argument value, and less than or equal to 6124. If the <var class="term">endCol</var> argument is omitted, its default value is 6124.<p><b>Note:</b> 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></tr> | ||
</table> | </table> | ||
Revision as of 02:27, 28 January 2011
Find next/previous item in Stringlist that matches a regex (Stringlist class)
These methods use a regular expression (regex) to locate an item in the method Stringlist. They return the item number of the first item that the regex matches. Both methods proceed item-by-item through the Stringlist. RegexLocate starts, by default, from item 1, the first item in the Stringlist; or it starts from the item you specify. RegexLocateUp starts from the item n
you specify and proceeds "upward" to item n-1, then n-2, and so on. RegexLocate and RegexLocateUp accept one required and five optional arguments, and may, optionally, return a number. They are callable methods.
Information about the regular expression matching rules observed is provided in Regex processing.
Syntax
[%itemNum =] sl:RegexLocate( regex, [startItem], [Options= string], - [Status= %output], [StartCol= number], - [EndCol= number]) Throws InvalidRegex
[%itemNum =] sl:RegexLocateUp( regex, [startItem], [Options= string], - [Status= %output], [StartCol= number], - [EndCol= number]) Throws InvalidRegex
Syntax terms
%itemNum | If specified, a numeric variable that is set to the number of the sl item matched by regex, or it is 0 if no items are matched. | ||||||||
---|---|---|---|---|---|---|---|---|---|
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. | ||||||||
startItem | The item number from which the regex matching is to begin. If this item is not matched, the method attempts to match the item with the next higher (if RegexLocate) or lower (if RegexLocateUp) item number, and so on. This numeric value is an optional argument that defaults to 1 (if RegexLocate) or to the number of items in sl (if RegexLocateUp). This value must not be negative and must not be greater than the number of sl items. Setting this argument to 0 is the same as setting it to 1. | ||||||||
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 the argument is specified, its value 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 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 the argument is specified, its value must be greater than or equal to 1, greater than or equal to the startCol argument value, and less than or equal to 6124. If the endCol argument is omitted, its default value is 6124. Note: If the endCol argument is omitted and a sl item exceeds 6124 bytes, the request is cancelled. |
Usage notes
- All errors in RegexLocate / RegexLocateUp, including invalid argument(s), will 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.
- The request is cancelled in any of these cases:
- You specify an invalid argument option.
- You omit the Status argument and a situation occurs that would cause a negative Status value.
- You omit the endCol argument and the length of an sl item exceeds 6124 bytes.
- For information about additional methods and $functions that support regular expressions, see Regex processing.
- The methods are available as of Sirius Mods Version 6.9.
Examples
-
In the following code fragment, RegexLocate is applied to the method Stringlist
%sl
to find the first occurrence of the string'CUST'
. If this is successful, the containing item is copied to a new Stringlist. The matching is done case-insensitively, and the starting item is the beginning of the list, by default. Substituting RegexLocateUp for RegexLocate in the example would find the last occurrence of'CUST'
.... %sl = new text to %sl %n = %list:findImageItem(%cust:ssn) if %n then %list:replaceImage(%n, 'CUST') else %list:addimage('CUST') end if end text %opt='i' %regex = '''cust''' %itemnum = %sl:RegexLocate(%regex, Options=%opt, Status=%st) If (%itemnum EQ 0) then Print 'Status from RegexLocate[Up] is ' %st Else Print %regex ' matches item ' %itemnum Print 'Now for %sl2 . . . ' %sl2 = new %i = %sl2:CopyItems(%sl, %itemnum, '1') %i = %sl2:Print End If ...