summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2006-11-01 12:25:18 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2006-11-01 12:25:18 +0000
commit9471bbcfa06a87dcb6803a36d1208c214fa56003 (patch)
treef5edcdab07ad4b718037fed3b15a7bbb3e4961f2 /Doc
parent22940: completion for mkdir (diff)
downloadzsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.tar
zsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.tar.gz
zsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.tar.bz2
zsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.tar.lz
zsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.tar.xz
zsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.tar.zst
zsh-9471bbcfa06a87dcb6803a36d1208c214fa56003.zip
22934, modified, see 22937: add HIST_SUBST_PATTERN option
make ${.../#%...} anchor at both ends
Diffstat (limited to 'Doc')
-rw-r--r--Doc/Zsh/expn.yo51
-rw-r--r--Doc/Zsh/options.yo9
2 files changed, 53 insertions, 7 deletions
diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo
index 6aa31c76a..584977c18 100644
--- a/Doc/Zsh/expn.yo
+++ b/Doc/Zsh/expn.yo
@@ -258,7 +258,8 @@ item(tt(s/)var(l)tt(/)var(r)[tt(/)])(
Substitute var(r) for var(l) as described below.
The substitution is done only for the
first string that matches var(l). For arrays and for filename
-generation, this applies to each word of the expanded text.
+generation, this applies to each word of the expanded text. See
+below for further notes on substitutions.
The forms `tt(gs/)var(l)tt(/)var(r)' and `tt(s/)var(l)tt(/)var(r)tt(/:G)'
perform global substitution, i.e. substitute every occurrence of var(r)
@@ -273,8 +274,8 @@ backslash.
)
enditem()
-The tt(s/l/r/) substitution works as follows. The left-hand side of
-substitutions are not regular expressions, but character strings. Any
+The tt(s/l/r/) substitution works as follows. By default the left-hand
+side of substitutions are not patterns, but character strings. Any
character can be used as the delimiter in place of `tt(/)'. A
backslash quotes the delimiter character. The character `tt(&)', in
the right-hand-side var(r), is replaced by the text from the
@@ -286,6 +287,41 @@ the rightmost `tt(?)' in a context scan can similarly be omitted.
Note the same record of the last var(l) and var(r) is maintained
across all forms of expansion.
+If the option tt(HIST_SUBST_PATTERN) is set, var(l) is treated as
+a pattern of the usual form desribed in
+ifzman(the section FILENAME GENERATION below)\
+ifnzman(noderef(Filename Generation)). This can be used in
+all the places where modifiers are available; note, however, that
+in globbing qualifiers parameter substitution has already taken place,
+so parameters in the replacement string should be quoted to ensure
+they are replaced at the correct time.
+Note also that complicated patterns used in globbing qualifiers may
+need the extended glob qualifier notation
+tt(LPAR()#q:s/)var(...)tt(/)var(...)tt(/RPAR()) in order for the
+shell to recognize the expression as a glob qualifer. Further,
+note that bad patterns in the substitution are not subject to
+the tt(NO_BAD_PATTERN) option so will cause an error.
+
+When tt(HIST_SUBST_PATTERN) is set, var(l) may start with a tt(#)
+to indicate that the pattern must match at the start of the string
+to be substituted, and a tt(%) may appear at the start or after an tt(#)
+to indicate that the pattern must match at the end of the string
+to be substituted. The tt(%) or tt(#) may be quoted with two
+backslashes.
+
+For example, the following piece of filename generation code
+with the tt(EXTENDED_GLOB) option:
+
+example(print *.c+LPAR()#q:s/#%+LPAR()#b+RPAR()s+LPAR()*+RPAR().c/'S${match[1]}.C'/+RPAR())
+
+takes the expansion of tt(*.c) and applies the glob qualifiers in the
+tt(LPAR()#q)var(...)tt(RPAR()) expression, which consists of a substitution
+modifier anchored to the start and end of each word (tt(#%)). This
+turns on backreferences (tt(LPAR()#b+RPAR())), so that the parenthesised
+subexpression is available in the replacement string as tt(${match[1]}).
+The replacement string is quoted so that the parameter is not substituted
+before the start of filename generation.
+
The following tt(f), tt(F), tt(w) and tt(W) modifiers work only with
parameter expansion and filename generation. They are listed here to
provide a single point of reference for all modifiers.
@@ -530,13 +566,14 @@ substituted as tt(${~opat}).
The var(pattern) may begin with a `tt(#)', in which case the
var(pattern) must match at the start of the string, or `tt(%)', in
-which case it must match at the end of the string. The var(repl) may
+which case it must match at the end of the string, or `tt(#%)' in which
+case the var(pattern) must match the entire string. The var(repl) may
be an empty string, in which case the final `tt(/)' may also be omitted.
To quote the final `tt(/)' in other cases it should be preceded by a
single backslash; this is not necessary if the
-`tt(/)' occurs inside a substituted parameter. Note also that the `tt(#)'
-and `tt(%)' are not active if they occur inside a substituted parameter,
-even at the start.
+`tt(/)' occurs inside a substituted parameter. Note also that the `tt(#)',
+`tt(%)' and `tt(#%) are not active if they occur inside a substituted
+parameter, even at the start.
The first `tt(/)' may be preceded by a `tt(:)', in which case the match
will only succeed if it matches the entire word. Note also the
diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo
index 02d8fa046..d4e1deeef 100644
--- a/Doc/Zsh/options.yo
+++ b/Doc/Zsh/options.yo
@@ -376,6 +376,15 @@ characters resulting from command substitution as being eligible for
filename generation. Braces (and commas in between) do not become eligible
for expansion.
)
+pindex(HIST_SUBST_PATTERN)
+item(tt(HIST_SUBST_PATTERN))(
+Substitutions using the tt(:s) and tt(:&) history modifiers are performed
+with pattern matching instead of string matching. This occurs wherever
+history modifiers are valid, including glob qualifiers and parameters.
+See
+ifzman(the section Modifiers in zmanref(zshexp))\
+ifnzman(noderef(Modifiers)).
+)
pindex(IGNORE_BRACES)
cindex(disabling brace expansion)
cindex(brace expansion, disabling)