The return value of “1” means it did match on your expression.
I’m actually not sure what regexp stores in the match variable. It wasn’t clear, at least to my eyes, in the documentation … “match will be set to the range of string that matched all of exp.“
If you want to capture the value, you’ll need to use parens and variables like this: regexp — {(b)} abdc match var1; puts $var1.
If you want to use the expression in a decision, do it like this: if {[regexp {b} abdc]} {…}.
we are going thru some regexp examples….understanding greedy vs non-greedy…and was wondering if in fact the above got a hit…..what did it get a hit on ?
Maybe it didn’t find the “b”. This expression returns a one as well:
Code:
regexp — {b?} acd match
That’s because the question mark means to match zero or one occurrences of the previous character. The pattern {b?} will always match any string.
Robert, I think that the reason you’re seeing this behavior is due to confusion about what greedy means. I think that it means that if it finds a match, it will try to use as many characters around that match as possible. However, if there are multiple matches, a greedy operator won’t match the longest one, it will just match the first one. In your case, every single character in the string matches your pattern, so it tries to match the first character, a. The greedy nature of the expression causes it to evaluate if it can match one occurance of “b” against the “a” instead of zero, but that fails.
You’ll see slightly different results with this test: