This is a basic explanation of the regular explanation syntax supported by the Regular Expression Component. What is presented here is just the main syntax without the possible variations that can be introduced by changing the ExpressionOptions and MatchOptions properties. The Help File that comes with the component presents a full and complete explanation of the supported syntax with all possible variations. This explanation is taken from the documentation for the underlying C++ generic regular expression library, which the Regular Expression Component uses, by Dr. John Maddock. I have left out any explanation here of Unicode support since that is not presently implemented by the Regular Expression Component.

Literals

All characters are literals except: ".", "*", "?", "+", "(", ")", "{", "}", "[", "]", "^" and "$". These characters are literals when preceded by a "\". A literal is a character that matches itself.

Wildcard

The dot character "." matches any single character.

Repeats

A repeat is an expression that is repeated an arbitrary number of times.

An expression followed by "*" can be repeated any number of times including zero.

An expression followed by "+" can be repeated any number of times, but at least once.

An expression followed by "?" may be repeated zero or one times only.

When it is necessary to specify the minimum and maximum number of repeats explicitly, the bounds operator "{}" may be used. Thus "a{2}" is the letter "a" repeated exactly twice, "a{2,4}" represents the letter "a" repeated between 2 and 4 times, and "a{2,}" represents the letter "a" repeated at least twice with no upper limit. These are all called repetition intervals. Note that there must be no white-space inside the {}, and there is no upper limit on the values of the lower and upper bounds.

Parentheses

Parentheses serve two purposes, to group items together into a sub-expression, and to mark what generated the match.

Alternatives

Alternatives occur when the expression can match either one sub-expression or another.

Each alternative is separated by a "|".

Sets

A set is a set of characters that can match any single character that is a member of the set. Sets are delimited by "[" and "]" and can contain literals, character ranges, character classes, collating elements and equivalence classes. Set declarations that start with "^" contain the compliment of the elements that follow.

Character literals are just the characters between the "[" and "]".

Character ranges are character two character separated with a "-" character and match any character between and including the two characters in the collating sequence.

Character classes are denoted using the syntax "[:classname:]" within a set declaration. The supported character classes are:

alnum Any alpha numeric character.

alpha Any alphabetical character a-z and A-Z. Other
characters may also be included depending upon
the locale.

blank Any blank character, either a space or a tab.

cntrl Any control character.

digit Any digit 0-9.

graph Any graphical character.

lower Any lower case character a-z. Other characters
may also be included depending upon the locale.

print Any printable character.

punct Any punctuation character.

space Any whitespace character.

upper Any upper case character A-Z. Other
characters may also be included depending upon
the locale.

xdigit Any hexadecimal digit character, 0-9, a-f and A-F.

word Any word character - all alphanumeric
characters plus the underscore.


Collating elements take the general form [.tagname.] inside a set declaration, where tagname is either a single character, or a name of a collating element, for example [[.a.]] is equivalent to [a], and [[.comma.]] is equivalent to [,]. All the standard POSIX collating element names are supported, and in addition the following digraphs: "ae", "ch", "ll", "ss", "nj", "dz", "lj", each in lower, upper and title case variations.

Equivalence classes take the general form [=tagname=] inside a set declaration, where tagname is either a single character, or a name of a collating element, and matches any character that is a member of the same primary equivalence class as the collating element [.tagname.]. An equivalence class is a set of characters that collate the same, a primary equivalence class is a set of characters whose primary sort key are all the same (for example strings are typically collated by character, then by accent, and then by case; the primary sort key then relates to the character, the secondary to the accentation, and the tertiary to the case). If there is no equivalence class corresponding to tagname, then [=tagname=] is exactly the same as [.tagname.].

Line Anchors

An anchor is something that matches the null string at the start or end of a line: "^" matches the null string at the start of a line, "$" matches the null string at the end of a line.

Back references

A back reference is a reference to a previous sub-expression that has already been matched. The reference is to what the sub-expression matched, not to the expression itself. A back reference consists of the escape character "\" followed by a digit "1" to "9", "\1" refers to the first sub-expression, "\2" to the second etc..

Characters by code

Characters by code consists of the escape character followed by the digit "0" followed by the octal character code. For example "\023" represents the character whose octal code is 23. Where ambiguity could occur use parentheses to break the expression up: "\0103" represents the character whose code is 103, "(\010)3 represents the character 10 followed by "3". To match characters by their hexadecimal code, use \x followed by a string of hexadecimal digits, optionally enclosed inside {}, for example \xf0 .

Word operators

The following operators are provided for compatibility with the GNU regular expression library.

"\w" matches any single character that is a member of the "word" character class, this is identical to the expression "[[:word:]]".
"\W" matches any single character that is not a member of the "word" character class, this is identical to the expression "[^[:word:]]".
"\<" matches the null string at the start of a word.
"\>" matches the null string at the end of the word.
"\b" matches the null string at either the start or the end of a word.
"\B" matches a null string within a word.

Buffer operators

The following operators are provide for compatibility with the GNU regular expression library, and Perl regular expressions:

"\`" matches the start of a buffer.
"\A" matches the start of the buffer.
"\'" matches the end of a buffer.
"\z" matches the end of a buffer.
"\Z" matches the end of a buffer, or possibly one or more new line characters followed by the end of the buffer.

Escape operator

The escape character "\" has several meanings.

Inside a set declaration the escape character is a normal character.

The escape operator may introduce an operator for example: back references, or a word operator.

The escape operator makes a special character normal, for example "\*" represents a literal "*" rather than the repeat operator.

The following escape sequences are aliases for single characters:

Escape Sequence Character Code Meaning
\a 0x07 Bell character
\f 0x08 Form feed
\n 0x0C Newline character
\r 0x0D Carriage return
\t 0x09 Tab character
\v 0x0B Vertical tab
\e 0x1B ASCII Escape character
\0dd 0dd An octal character code,where dd is one or more octal digits.
\xXX 0xXX A hexadecimal character code,where XX is one or more hexadecimal digits.
\cZ z-@ An ASCII escape sequence control-Z, where Z is any ASCII character greater than or equal to the character code for '@'.

The following are miscellaneous escape sequences for Perl compatibility:

Escape Sequence Meaning
\w Equivalent to [[:word:]]
\W Equivalent to [^[:word:]]
\s Equivalent to [[:space:]]
\S Equivalent to [^[:space:]]
\d Equivalent to [[:digit:]]
\D Equivalent to [^[:digit:]]
\l Equivalent to [[:lower:]]
\L Equivalent to [^[:lower:]]
\u Equivalent to [[:upper:]]
\U Equivalent to [^[:upper:]]
\C Any single character, equivalent to '.'
\Q The begin quote operator, everything that follows is treated as a literal character until a \E end quote operator is found.
\E The end quote operator, terminates a sequence begun with \Q.