Tutorial by Examples

The regexp command is used to match a regular expression against a string. # This is a very simplistic e-mail matcher. # e-mail addresses are extremely complicated to match properly. # there is no guarantee that this regex will properly match e-mail addresses. set mydata "send mail to john....
If you have a greedy match as the first quantifier, the whole RE will be greedy, If you have non-greedy match as the first quantifier, the whole RE will be non-greedy. set mydata { Device widget1: port: 156 alias: input2 Device widget2: alias: input1 Device widget3: port: 238 alias...
The regsub command is used for regular expression matching and substitution. set mydata {The yellow dog has the blues.} # create a new string; only the first match is replaced. set newdata [regsub {(yellow|blue)} $mydata green] puts $newdata The green dog has the blues. # replace the data in t...
\m : Beginning of a word. \M : End of a word. \y : Word boundary. \Y : a point that is not a word boundary. \Z : matches end of data. Documentation: re_syntax
Sometimes you need to match a literal (sub-)string with a regular expression despite that substring containing RE metacharacters. While yes, it's possible to write code to insert appropriate backslashes to make that work (using string map) it is easiest to just prefix the pattern with ***=, which ma...

Page 1 of 1