doc: elaborate about regex matching on pattern space

Regex addresses work on current pattern space, not on the original
input lines. From https://bugs.debian.org/284646

* doc/sed.texi (Regexp Addresses): Add a paragraph and an example.
* doc/sed.x (Addresses): Add a sentence about regexp.
This commit is contained in:
Assaf Gordon committed 2017-02-24 00:49:20 -05:00
1 parent a805d57e1f
commit de6b6ccd74
2 files changed
+29

No files matched your search

+27
View File
@@ -2265,6 +2265,33 @@ the period character does not match a new-line character in
multi-line mode.
@end table
@cindex regex addresses and pattern space
@cindex regex addresses and input lines
Regex addresses operate on the content of the current
pattern space. If the pattern space is changed (for example with @code{s///}
command) the regular expression matching will operate on the changed text.
In the following example, automatic printing is disabled with
@option{-n}. The @code{s/2/X/} command changes lines containing
@samp{2} to @samp{X}. The command @code{/[0-9]/p} matches
lines with digits and prints them.
Because the second line is changed before the @code{/[0-9]/} regex,
it will not match and will not be printed:
@codequoteundirected on
@codequotebacktick on
@example
@group
$ seq 3 | sed -n 's/2/X/ ; /[0-9]/p'
1
3
@end group
@end example
@codequoteundirected off
@codequotebacktick off
@node Range Addresses
@section Range Addresses
+2
View File
@@ -257,6 +257,8 @@ Match the last line.
.RI / regexp /
Match lines matching the regular expression
.IR regexp .
Matching is performed on the current pattern space, which
can be modified with commands such as ``s///''.
.TP
.BI \fR\e\fPc regexp c
Match lines matching the regular expression