tcl Regular Expressions

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

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

Remarks

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.



Got any tcl Question?