Subset (Regex function)

From m204wiki
Revision as of 21:05, 24 March 2022 by Alex (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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