Re: Regular expressions question



Kevin Walzer schrieb:
I'm trying to parse some strings for a specific pattern with regular expressions, and I'm having a bit of difficulty with the syntax. My procedure takes a number, puts it into a variable "$catnum", and then looks for a match with regex:

if {[regexp "\($catnum\)" [lindex $item 0]]}

You need to anchor the regexp with ^ and $, otherwise the semamtics is "contains a match", not "matches exactly". But in your example, you don't make any use of the regexp features. You could compare it directly like

if { "($catnum)" == [lindex $item 0]]}

This should be faster also.

Christian
.