Partager via


Atomic Zero-Width Assertions 

The metacharacters described in the following table do not cause the engine to advance through the string or consume characters. They simply cause a match to succeed or fail depending on the current position in the string. For instance, ^ specifies that the current position is at the beginning of a line or string. Thus, the regular expression ^FTP returns only those occurrences of the character string "FTP" that occur at the beginning of a line.

Assertion Description

^

Specifies that the match must occur at the beginning of the string or the beginning of the line. For more information, see the Multiline option in Regular Expression Options.

$

Specifies that the match must occur at the end of the string, before \n at the end of the string, or at the end of the line. For more information, see the Multiline option in Regular Expression Options.

\A

Specifies that the match must occur at the beginning of the string (ignores the Multiline option).

\Z

Specifies that the match must occur at the end of the string or before \n at the end of the string (ignores the Multiline option).

\z

Specifies that the match must occur at the end of the string (ignores the Multiline option).

\G

Specifies that the match must occur at the point where the previous match ended. When used with Match.NextMatch(), this ensures that matches are all contiguous.

\b

Specifies that the match must occur on a boundary between \w (alphanumeric) and \W (nonalphanumeric) characters. The match must occur on word boundaries (that is, at the first or last characters in words separated by any nonalphanumeric characters). The match can also occur on a word boundary at the end of the string.

\B

Specifies that the match must not occur on a \b boundary.

See Also

Reference

Regular Expression Options

Other Resources

Regular Expression Language Elements