What are back references?
back-references are regular expression commands which refer to a previous part of the matched regular expression. Back-references are specified with backslash and a single digit (e.g. ‘ \1 ‘). The part of the regular expression they refer to is called a subexpression, and is designated with parentheses.
What does 1+ mean in regex?
\1 – it means the first capturing group in the matched expression. \n would be the nth capturing group. (Note that \0 would be whole match). In many engines, the upperlimit for n is 9, but some support up to 99 as well.
When to use back references and subexpressions in SED?
Back-references and subexpressions are used in two cases: in the regular expression search pattern, and in the replacement part of the s command (see Regular Expression Addresses and The “s” Command ). In a regular expression pattern, back-references are used to match the same content as a previously matched subexpression.
When to use back references in replacement part?
In the s command, back-references can be used in the replacement part to refer back to subexpressions in the regexp part. The following example uses two subexpressions in the regular expression to match two space-separated words. The back-references in the replacement part prints the words in a different order:
Which is part of a regular expression does a back reference refer to?
back-references are regular expression commands which refer to a previous part of the matched regular expression. Back-references are specified with backslash and a single digit (e.g. ‘ 1 ’). The part of the regular expression they refer to is called a subexpression, and is designated with parentheses.
When to use back references in regexp replacement?
In the s command, back-references can be used in the replacement part to refer back to subexpressions in the regexp part. The following example uses two subexpressions in the regular expression to match two space-separated words.