How to control the overal mode of a regular expression.
Special groups
This page describes how to create special groups including metatoken groups, conditional groups and comment groups.
Character
Description
Example
Ways to define groups which act as metatokens
(?=expn-text)
This group matches the expression that it contains, but it matches as a position between an arbitary character in the search text and the actual text that it finds afterwards. This group type does not create referrable match text, nor does it contribute to the group index described above.
t(?=s)
matches the second
t
in
straits
.
(?!expn-text)
This group behaves in identical manner to the previous one, with the exeption that it will only match externally when it does not match internally.
t(?!s)
matches the first
t
in
straits
.
(?<=simple-text)
This group matches the expression that it contains, but it matches as a position between an arbitary character in the search text and the actual text that it finds beforehand. This group type does not create referrable match text, nor does it contribute to the group index described above. This group works only with simple text, or literal, tokens.
(?<=s)t
matches the first
t
in
straits
.
(?<!simple-text)
This group behaves in identical manner to the previous one, with the exeption that it will only match externally when it does not match internally.
(?<!s)t
matches the second
t
in
straits
.
Ways to define conditional groups
(?(?=expn-text)then|else)
This group type has the capability to select one of a pair of token groups separated by a pipe, on the basis of a conditional group. If the conditional group, the first child group of the conditional group, succeeds in matching it's content then the first of the pipe separated groups is tested. Otherwise the second group is tested.
(?(?<=a)b|c)
matches the second
b
and the first
c
in
babxcac
(?(expn-text)then|else)
The contitional group may be any valid group.
(?(a)b|c)
matches
ab
, the first
c
and the second
c
in
babxcac
Ways to make comments in regular expressions
(?#comment-text)
This type of group ignores it's content completely. This group type can be used to comment regular expressions.