Reputation:
I have a question about the following regular expression:
I want to match the following string: employee Type="entry" id="mmop" location="somewhere"
using the RE as following:
if {[regexp {id=(".*")} $data -> Id]} {
#do something here
}
but the result I get is "entry" id="mmop" location="somewhere"
, how to fix it?
Upvotes: 1
Views: 111
Reputation: 324820
Add ?
after the *
, or replace .
with [^"]
. The problem is caused by the .*
being greedy, grabbing everything it can while still matching the pattern.
Upvotes: 4