Product Site

5.4.15. RegularExpression Class

This class provides support for regular expressions. A regular expression is a pattern you can use to match strings.

Note

The RegularExpression class is not a built-in class and is not preloaded. Use ::requires "rxregexp.cls" to activate its functionality.
Table 5.50. RegularExpression Class
Object
Methods inherited from the Object class
Class (Metaclass)
Methods inherited from the Class class
RegularExpression
new (Class Method)
matchpos 
parseposition 

Here is a description of the syntax:
|

OR operator between the left and right expression
?

Matches any single character
*

Matches the previous expression zero or more times
+

Matches the previous expression one or more times
\

"Escape" symbol: use the next character literally
()

Expression in parentheses (use where needed)
{n}

Matches previous expression n times (n > 1)
[]

Set definition: matches any single character out of the defined set.

A "^" right after the opening bracket means that none of the following characters should be matched.

A "-" (if not used with "\") defines a range between the last specified character and the one following "-". If it is the first character in the set definition, it is used literally.

The following symbolic names (they must start and end with ":") can be used to abbreviate common sets:
:alpha:

Characters in the range A-Z and a-z
:lower:

Characters in the range a-z
:upper:

Characters in the range A-Z
:digit:

Characters in the range 0-9
:alnum:

Characters in :digit: and :alpha:
:xdigit:

Characters in :digit:, A-F and a-f
:blank:

Space and tab characters
:space:

Characters '09'x to '0d'x and space
:cntrl:

Characters '00'x to '1f'x and '7f'x
:print:

Characters in the range '20'x to '7e'x
:graph:

Characters in :print: without space
:punct:

All :print: characters without space and not in :alnum:
Example 5.273. RegularExpression class
::requires "rxregexp.cls"

/*
     "(Hi|Hello) World"      Matches "Hi World" and
                             "Hello World".
     "file.???"              Matches any file with three
                             characters after "."
     "file.?{3}"             Same as above.
     "a *b"                  Matches all strings that begin with
                             "a" and end with "b" and have an
                             arbitrary number of spaces in between
                             both.
     "a +b"                  Same as above, but at least one space
                             must be present.
     "file.[bd]at"           Matches "file.bat" and "file.dat".
     "[A-Za-z]+"             Matches any string containing only
                             letters.
     "[:alpha:]+"            Same as above, using symbolic names.
     "[^0-9]*"               Matches any string containing no
                             numbers, including the empty string.
     "[:digit::lower:]"      A single character, either a digit or
                             a lower case character.
     "This is (very )+nice." Matches all strings with one or more
                             occurrences of "very " between
                             "This is " and "nice.".
*/