• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

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!
0
kitwei
Asked:
kitwei
  • 2
1 Solution
 
ozoCommented:
$text =~ /abc="(.*?)"/;
or
$text =~ /abc="([^"]*)/";
0
 
ozoCommented:
sorry, /abc="([^"]*)/" should have been /abc="([^"]*)"/
0
 
kitweiAuthor Commented:
Excellent! Thank you!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now