Top  Previous  Next

Scripts > Class elements and c++ instructions > Parser class methods > Parser state > Sub-expressions


Parenthesis "(...)" in regular expressions can be used to mark sections of text, which are recognized by the sub-expressions of a regular expression.


By means of an index parameter for the functions str and length the text or the length of sub-expressions can be accessed

The whole recognized text is returned by the call of xState.str() or xState.str(0). xState.str(1) returns the section of text, which was recognized by the sub-expression with the index 1.


The index of a sub-expression is the number of its opening parenthesis inside of the whole expression. The counting begins from left to right with the index 1.


In the menu help an item Regex test exists, where you can open a dialog, which presents a simple possibility to investigate the sub expressions of a regular expression.


Following indices are defined:



- 2

everything from the end of the match, to the end of the input string

- 1

the ignored characters in front of the actual recognized token


the actual recognizes section of text

0 < N < size()

the section of text, which was recognized by the N'th sub expression of the actual recognized token

N < -2 or N >= size()

Represents an out-of range non-existent sub-expression: an empty string






the expression:




may be applied to




Then xState.str(1) would contain the last "ab" of the text.


Sub-expressions can match empty strings. For example a sub-expression can be part of an alternative, which doesn't match text.



This page belongs to the TextTransformer Documentation

Home  Content  German