|
DEELX Extended Syntax: Conditional Expression
Return: Content | Prev: Independent expression | Next: Recursive expression
Conditional Expression
According to a certain condition, conditional expression matches one of two options.
Remarks
The condition can be:
- Whether a certain group captured or not.
- Whether a certain expression can match at current position or not.
Conditional expression and description:
Expression |
Characteristic |
Description |
(?(1)yes|no) |
Is number |
If group 1 captured, match yes, or else match no |
(?(?=a)aa|bbb) |
Assertion |
If next char is 'a', match aa, or else match bbb |
(?(xxx)aa|bbb) |
Not named group |
If there is no named group 'xxx', same as (?=xxx)
|
(?(name)yes|no) |
Is named group |
If there is named group 'name', captured or not |
More:
- If it is RIGHTTOLEFT mode, (?(xxx)aa|bbb)
is same as (?(?<=xxx)aa|bbb)
.
- If there is only one option, the option will do match if the condition success.
- If there are more than 2 options separated by "|", only the first "|" is regarded as conditional expression's separator. For example: (?(?=xxx)yes|no1|no2),
if condition success, "yes" matches, or "no1|no2" matches.
|
|
|