tclRegular Expressions


  • regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?
  • regsub ?switches? exp string subSpec ?varName?


This topic is not intended to discuss regular expressions themselves. There are many resources on the internet explaining regular expressions and tools to help build regular expressions.

This topic will try to cover the common switches and methods of using regular expressions in Tcl and some of the differences between Tcl and other regular expression engines.

Regular expressions are generally slow. The first question you should ask is "Do I really need a regular expression?". Only match what you want. If you don't need the other data, don't match it.

For the purposes of these regular expression examples, the -expanded switch will be used in order to be able to comment and explain the regular expression.