Locate and LocateUp (Regex function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
Line 10: Line 10:
<tr><th>regex</th>
<tr><th>regex</th>
<td>The <var>Regex</var> object</td></tr>
<td>The <var>Regex</var> object</td></tr>
<tr><th>stringlist</th>
<tr><th>sl</th>
<td>The <var>Stringlist</var> to be searched</td></tr>
<td>The <var>Stringlist</var> to be searched</td></tr>
<tr><th>startItem</th>
<tr><th>startItem</th>
Line 19: Line 19:
<td>number<br/>The last column to include in the attempted match. The default value is effectively the value of the [MaxItemLength (Stringlist property)|Stringlist MaxItemLength property].</td></tr>
<td>number<br/>The last column to include in the attempted match. The default value is effectively the value of the [MaxItemLength (Stringlist property)|Stringlist MaxItemLength property].</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>

Revision as of 14:54, 24 March 2022

Find next item in Stringlist that matches a regex (Regex class)


These functions search a Stringlist for an item that matches the regular expression in the Regex object. Locate searches forward (low to high item number) in the Stringlist while LocateUp searches backward.

Syntax

[%itemNum =] regex:Locate( sl, [startItem], [StartCol= number], - [EndCol= number])

[%itemNum =] regex:LocateUp( sl, [startItem], [StartCol= number], - [EndCol= number])

Syntax terms

%itemNumThe first matching item number. If no items match, 0 (zero) is returned.
regex The Regex object
sl The Stringlist to be searched
startItem The item number at which to start searching. If 0 (the default), searching begins from the first item for Locate and the last item for LocateUp. Otherwise, startItem must be a number from 1 to the number of items in the Stringlist, inclusive.
StartCol number
The first column to include in the attempted match. The default value is 1.
EndCol number
The last column to include in the attempted match. The default value is effectively the value of the [MaxItemLength (Stringlist property)|Stringlist MaxItemLength property].

Usage notes

  • These functions have identical functionality to the ][RegexLocate and RegexLocateUp (Stringlist functions)|Stringlist RegexLocate and RegexLocateUp]] functions.
  • Invalid values for parameters (such as start column greater than end column) result in request cancellation.

Examples

The following example removes all items that match regular expression "(foo|fu)bar" (case insensitive) from a Stringlist:

%num is float %regex is object regex %sl is object stringlist ... %regex = new("(fu|foo)bar", options="i") %num = 1 repeat while %num le %sl:count %num = %regex:locate(%sl, %num) if %num eq 0 then loop end; end if %sl:removeItem(%num) end repeat

See also