Groupings

Top  Previous  Next

Scripts > Token definitions > Regular expressions > Groupings

 

Parentheses serve two purposes:

 

1. To group items together into a sub-expression

 

If expressions are grouped into a sub-expression, operators like the repetition operator, can be applied to the whole group. For example the expression "(ab)*" would match all of the string "ababab".

 

 

2. To mark what generated the match

 

When the whole expression has matched, both informations can be accessed (via xState):  on what the whole expression matched and on what each sub-expression matched. Sub-expressions are indexed from left to right starting from 1; sub-expression 0 is the whole expression. The according parts of text are obtained by

 

str s = xState.str(index);

 

It is permissible for sub-expressions to match null strings. If a sub-expression takes no part in a match - for example if it is part of an alternative that is not taken - then xState.str(index) will return an empty string.

 

 

 

 

 

 



This page belongs to the TextTransformer Documentation

Home  Content  German