contents   index   previous   next



Regular expression reference characters

Character

Meaning

 

|

Or. Match the character or sub pattern on the left or the character or sub pattern on the right.

 

\n

Reference to group. Match the same characters, not the regular expression itself, matched by group n. Groups are sub patterns that are contained in parentheses. Groups may be nested. Groups are numbered according to the order in which the left parenthesis of a group appears in a regular expression.

 

(...)

Group with capture. Characters inside of parentheses are handled as a single unit or sub pattern in specified ways, such as with the first two explanations, | and \n, in this table. The characters that are actually matched are captured and may be used later in an expression (as with \n) or in a replacement expression (as with $n). For example, if the string "one two three two one" and the pattern /(o.e).+(w.+?e)/ are used, then the back references $1 or \1 use the text "one".

 

(?:...)

Group without capture. Matches the same text as (...), but the text matched is not captured or saved and is not available for later use using \n or $n. The overhead of not capturing matched text becomes important in faster execution time for searches involving loops and many iterations. Also, some expressions and replacements can be easier to read and use with fewer numbered back references with which to keep up. For example, if the string "one two three two one" and the pattern /(?:o.e).+(w.+?e)/ are used, then the back references $1 or \1 use the text "wo thre".

 

(?=...)

Positive look ahead group without capture. The position of the match is at the beginning of the text that matches the sub pattern. For example, /ScriptEase (?=Desktop|ISDK)/ matches "ScriptEase " in "ScriptEase Desktop" or "ScriptEase ISDK", but not "ScriptEase " in "ScriptEase Web Server". When a search continues, it begins after "ScriptEase ", not after "Desktop" or "ISDK". That is, the search continues after the last text matched, not after the text that matches the look ahead sub pattern.

 

(?!...)

Negative look ahead group without capture. The position of the match is at the beginning of the text not matching the sub pattern. For example, /ScriptEase (?!Desktop|ISDK)/ matches "ScriptEase " in "ScriptEase Web Server", but not "ScriptEase " in "ScriptEase Desktop" or "ScriptEase ISDK". When a search continues, it begins after "ScriptEase ", not after "Desktop" or "ISDK". That is, the search continues after the last text matched, not after the text that matches the look ahead sub pattern.

 


Regular expression escape sequences