Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Answer: Double quotes within double quotes

( #6884=categorized answer: print w/ replies, xml ) Need Help??

Q&A > regular expressions > How can I find nested delimiters? contributed by btrott

my $query = qq("SOME QUERY WITH "" (DOUBLE QUOTES)" YEEHA); if ($query =~ /"(.*)"(.*)/) { my $inside = $1; my $outside = $2; print $inside, "\n", $outside, "\n"; }
This works because the regex is greedy.

But I'm not sure if this is really what you want-- was that query merely an example, or is that really what all your queries look like?

If it's the former, and you're trying to do something more complicated than what you describe above--for example, match balanced text--you might take a look at perlfaq6, Can I use Perl regular expressions to match balanced text?.

Also, see Text::Balanced on CPAN. -- Ed.

Comment on Answer: Double quotes within double quotes
Download Code
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (14)
As of 2015-11-25 12:18 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (674 votes), past polls