Arbortext Command Language > Using the Arbortext Command Language > Using Regular Expressions > Grouping
  
Grouping
You can use parentheses ( ) to group search criteria, such as s(a|e)t. The alternate specification (a|e) is a grouped term, producing matches for “sat” and “set”.
You can group an expression into a unit within a larger expression and then apply one of the repetition characters to the group, such as ?, +, *, or the alternation character |. For example, /java(script)?/ matches “java” as well as “javascript”. The regular expression "(0|1)+" matches a string of one or more 0 characters or one or more 1 characters.
For the replacement string to the substitute command or the sub or gsub functions, the \n combination can be specified to reference a specific group within parentheses in the matched result. The n represents the group number by counting groups from left to right. For example, substitute '(John)(Smith)'\2,\1' -e reverses the two groups as Smith, John.
The combination \0 represents the entire matched result. For example:
substitute -e -nom 'tag'<\0>'
would surround the next occurrence of “tag” with angle brackets. The -nom option prevents the angle brackets in the replacement string from being interpreted as markup.
The \n combination can not be used in the regular expression itself.