(Created page with "<seo title="Groups and Replacement Strings | vEdit" description="Learn special matching characters to use in both the search string and replacement string of a regular expres...") |
|||
| Line 18: | Line 18: | ||
;^{.*}\N\1$ | ;^{.*}\N\1$ | ||
:Matches two identical lines which occur together. (Can be used to find duplicate lines after sorting.) | :Matches two identical lines which occur together. (Can be used to find duplicate lines after sorting.) | ||
| + | |||
| + | ===Precedence=== | ||
| + | |||
| + | The order of precedence of the regular expressions operators is: | ||
| + | |||
| + | ;Highest to Lowest | ||
| + | :''\\'' > '''[ ]''' > '''* + ?''' > '''{ }''' > '''Concatenations''' > '''|''' | ||
| + | |||
| + | ==Groups and Replacement Examples== | ||
==Related Resources== | ==Related Resources== | ||
The special symbols “{” and “}” group regular expressions for reference purposes. They permit the text matched by the expression within “{ }” to be referenced again in the search string or to be included as part of the replacement text.
An expression may contain up to 9 groups which are referenced by number, “\1” through “\9”. The groups are numbered in the order of their opening “{”.Groups may also be nested. Groups may be referenced in either a latter part of the regular expression or in the replacement string. This allows portions of the matched text to be used as parts of the replacement text.
The character “&” has a special meaning only in a replacement string and references the entire text matched by the search.
Consider the expression “the {man}|the {woman}”. If the matched text is “the man”, “\1” is “man” and “\2” is empty (null). Now consider the expression “{the {[a-z]+}} has”. If the matched text is “the woman has”, “\1” is “thewoman” and “\2” is “woman”.
The order of precedence of the regular expressions operators is: