Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

What do you call a back reference in sed?


Asked by Rodney Hill on Dec 11, 2021 FAQ



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.
One may also ask,
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.
In respect to this, To know how to use sed, you should understand regular expressions ("regexp" for short). A regular expression is a pattern that is matched against a subject string from left to right. Most characters are ordinary: they stand for themselves in a pattern, and match the corresponding characters in the subject.
In this manner,
Here is a brief description of regular expression syntax as used in sed: A single ordinary character matches itself. Matches a sequence of zero or more instances of matches for the preceding regular expression, which must be an ordinary character, a special character preceded by " \ ", a ". ", a grouped regexp (see below ), or a bracket expression.
And,
A sed program consists of one or more sed commands, passed in by one or more of the -e, -f, --expression, and --file options, or the first non-option argument if zero of these options are used. This document will refer to “the” sed script; this is understood to mean the in-order concatenation of all of the script s and script-file s passed in.