NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Backreferences

Parsing details. The expressions \1 through \9 always refer to backreferences, not octal codes. Multidigit expressions \11 and upward are considered backreferences if there is a backreference corresponding to that number; otherwise, they are interpreted as octal codes (unless the starting digits are 8 or 9, in which case they are treated as literal "8" and "9"). If a regular expression contains a backreference to an undefined group number, it is considered a parsing error. Users should note that if the ambiguity is a problem, the \k<n> notation is unambiguous and cannot be confused with octal character codes; similarly, hexadecimal codes \xdd are unambiguous and cannot be confused with backreferences.

Matching details. A backreference refers to the most recent definition of a group (when matching left-to-right, that is the definition most immediately to the left). Specifically, when a group makes multiple captures due to quantifiers or multiple parentheses, a backreference refers to the most recent capture. For example, (?<1>a)(?<1>\1b)* matches aababb, with capturing pattern (a)(ab)(abb). Looping quantifiers do not clear group definitions.

If a group has not captured any substring, a backreference to that group is undefined and never matches. For example, the expression \1() never matches anything, but the expression ()\1 matches the empty string.