regexp
regexp ?-option ...? exp string ?matchVar? ?subMatchVar ...?
Finds the regular expression exp in string. It gives 1 for a match and 0 for no match, and sets matchVar to the match and each subMatchVar to a group. Put exp in braces, so that Tcl does not change its backslashes.
Options
| Option | What it does |
|---|---|
-nocase |
Matches letters with no case. |
-all |
Finds each match. It gives the count of matches. |
-inline |
Gives the match and its groups as a list, and sets no variable. With -all, each match and its groups. |
-indices |
Gives the start and end index of each match in place of the text. |
-start INDEX |
Starts the search at INDEX. |
-line |
^ and $ match at each line, and . does not match a newline. |
-expanded |
White space and # comments in exp are ignored. |
-about |
Gives the count of groups and the flags of exp. |
Examples
A click on an example runs it in the shell of the page.
regexp -inline {(\d+)-(\d+)} "pages 12-40":12-40 12 40regexp -all -inline {#\w+} "a #b c #d":{#b} #dregexp {^\d+$} 42abc:0
Errors
regexp {(} xgives the errorcouldn't compile regular expression pattern: parentheses () not balanced
Facts
- Capability: none.
- Compute cost: one compute unit for the call, and more for the commands that it runs.