in reply to Regex: Matching quoted text

Assuming you are running 5.10.0, 5.10.1, 5.12.0, or 5.12.1, use
/(?|"([^"]+)"|(-))/
that should put the match in $1, regardless which alternation matched.

If you are using a pre-5.10 perl, consider this a good reason to upgrade.

Replies are listed 'Best First'.
Re^2: Regex: Matching quoted text
by Anonymous Monk on Jun 04, 2010 at 13:38 UTC

    Ugh........I'm using CentOS on this server and even at the latest relase they only have 5.8 in the repos. Is there anyway to do a similar regex without using that?

        I don't think Text::Balanced would help since I already know how to extract the text from between quotes, I just need to know what to do if there is no quotes.

      Not if you want the match to show up in $1, regardless of which alternation matched. If it was possible beforehand, 5.10 would not have introduced the (?|) construct.