[GSOC idea] enhance regular expressions?

bearophile bearophileHUGS at lycos.com
Mon Mar 28 15:40:52 PDT 2011


Dmitry Olshansky:

> BTW which ones? Now is the time to propose them.

Verbose regular expressions, that allow to put space and comments, to format REs more like code and less like a cryptic puzzle language.

(?:...) A non-grouping version of regular parentheses. Matches whatever regular expression is inside the parentheses, but the substring matched by the group cannot be retrieved after performing a match or referenced later in the pattern.

(?P<name>...) Similar to regular parentheses, but the substring matched by the group is accessible via the symbolic group name name. A symbolic group is also a numbered group.

(?P=name) Matches whatever text was matched by the earlier group named name.

(?=...) Lookahead assertion. Matches if ... matches next, but doesn't consume any of the string.

(?!...) Negative lookahead assertion. Matches if ... doesn't match next. The contained pattern must only match strings of some fixed length.

(?<=...) Positive lookbehind assertion. Matches if the current position in the string is preceded by a match for ... that ends at the current position. The contained pattern must only match strings of some fixed length.

(?<!...) Negative lookbehind assertion. Matches if the current position in the string is not preceded by a match for .... The contained pattern must only match strings of some fixed length. Patterns which start with negative lookbehind assertions may match at the beginning of the string being searched.

Bye,
bearophile


More information about the Digitalmars-d mailing list