summaryrefslogtreecommitdiffstats
path: root/doc/regsub.n
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2004-10-27 14:23:38 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2004-10-27 14:23:38 (GMT)
commitb2fde4ffc30a75e9e937b7522cd07a298116bc62 (patch)
treef7746a2a8316d612570e1456524e3d182e855c82 /doc/regsub.n
parent3ec9fd99b36055e6d272e64c1de04a93fdc9416b (diff)
downloadtcl-b2fde4ffc30a75e9e937b7522cd07a298116bc62.zip
tcl-b2fde4ffc30a75e9e937b7522cd07a298116bc62.tar.gz
tcl-b2fde4ffc30a75e9e937b7522cd07a298116bc62.tar.bz2
Yet more doc update backporting
Diffstat (limited to 'doc/regsub.n')
-rw-r--r--doc/regsub.n30
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