user707549
user707549

Reputation:

why this regular expression does not match

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

Answers (1)

Niet the Dark Absol
Niet the Dark Absol

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

Related Questions