Solved

regex question

Posted on 2002-05-13
3
184 Views
Last Modified: 2010-03-05
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
Comment
Question by:kitwei
  • 2
3 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
$text =~ /abc="(.*?)"/;
or
$text =~ /abc="([^"]*)/";
0
 
LVL 84

Accepted Solution

by:
ozo earned 100 total points
Comment Utility
sorry, /abc="([^"]*)/" should have been /abc="([^"]*)"/
0
 

Author Comment

by:kitwei
Comment Utility
Excellent! Thank you!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now