diff options
author | dkf <donal.k.fellows@manchester.ac.uk> | 2004-10-27 14:23:38 (GMT) |
---|---|---|
committer | dkf <donal.k.fellows@manchester.ac.uk> | 2004-10-27 14:23:38 (GMT) |
commit | 45beb64f7dcb09a6ce83532702bca760f72e6f4d (patch) | |
tree | f7746a2a8316d612570e1456524e3d182e855c82 /doc/regsub.n | |
parent | 5bc57d7b0f63d86fc383565d69f7704943fff94d (diff) | |
download | tcl-45beb64f7dcb09a6ce83532702bca760f72e6f4d.zip tcl-45beb64f7dcb09a6ce83532702bca760f72e6f4d.tar.gz tcl-45beb64f7dcb09a6ce83532702bca760f72e6f4d.tar.bz2 |
Yet more doc update backporting
Diffstat (limited to 'doc/regsub.n')
-rw-r--r-- | doc/regsub.n | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/doc/regsub.n b/doc/regsub.n index d0c6e01..cccb2e4 100644 --- a/doc/regsub.n +++ b/doc/regsub.n @@ -6,7 +6,7 @@ '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" -'\" RCS: @(#) $Id: regsub.n,v 1.9 2003/02/20 15:33:02 dkf Exp $ +'\" RCS: @(#) $Id: regsub.n,v 1.9.2.1 2004/10/27 14:23:58 dkf Exp $ '\" .so man.macros .TH regsub n 8.3 Tcl "Tcl Built-In Commands" @@ -114,9 +114,35 @@ string after replacement is returned. .VE 8.4 See the manual entry for \fBregexp\fR for details on the interpretation of regular expressions. +.SH EXAMPLES +Replace (in the string in variable \fIstring\fR) every instance of +\fBfoo\fR which is a word by itself with \fBbar\fR: +.CS +\fBregsub\fR -all {\e<foo\e>} $string bar string +.CE +.PP +Insert double-quotes around the first instance of the word +\fBinteresting\fR, however it is capitalised. +.CS +\fBregsub\fR -nocase {\e<interesting\e>} $string {"&"} string +.CE +.PP +Convert all non-ASCII and Tcl-significant characters into \eu escape +sequences by using \fBregsub\fR and \fBsubst\fR in combination: +.CS +# This RE is just a character class for everything "bad" +set RE {[][{}\e$\es\eu0100-\euffff]} + +# We will substitute with a fragment of Tcl script in brackets +set substitution {[format \e\e\e\eu%04x [scan "\e\e&" %c]]} + +# Now we apply the substitution to get a subst-string that +# will perform the computational parts of the conversion. +set quoted [subst [\fBregsub\fR -all $RE $string $substitution]] +.CE .SH "SEE ALSO" -regexp(n), re_syntax(n) +regexp(n), re_syntax(n), subst(n) .SH KEYWORDS match, pattern, regular expression, substitute |