Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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 exploiting the Monastery: (6)
As of 2015-10-07 21:51 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (201 votes), past polls