Introduction

Syntax

Program Help

Examples

Download

Match Tool 2.1

Match Tool 3.0

 

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:

  1. Whether a certain group captured or not.
  2. 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:

  1. If it is RIGHTTOLEFT mode,  (?(xxx)aa|bbb) is same as (?(?<=xxx)aa|bbb) .
  2. If there is only one option, the option will do match if the condition success.
  3. 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.

 

 

RegExLab.com © 2005 - All Rights Reserved