Link to home
Start Free TrialLog in
Avatar of kitwei
kitwei

asked on

regex question

Hi, I'm having trouble with this regex. Here is what I do:

$text = 'abc="123" def="456"';

$text =~ s/abc="(.*)"/;

print $1;

the value of $1 I get is
123" def="456
but I only want 123. I actually don't know the string within the quote, it could be anything. The thing I know is abc="<string>" and def="<string>"
How do I specify such that the second quote of "(.*)" is the next quote, instead of the last quote of the wholte string?

Any idea? Thanks much!
Avatar of ozo
ozo
Flag of United States of America image

$text =~ /abc="(.*?)"/;
or
$text =~ /abc="([^"]*)/";
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kitwei
kitwei

ASKER

Excellent! Thank you!