in reply to [regex] matching Perl quoted strings

It ain't simple. Your 'dumb' way isn't correct. Consider that the following are valid Perl strings too:
q [Jon [Maddog] Orwant]; q "Jon \"Maddog\" Orwant";
Your regex doesn't match any of them correctly.

You might be best off using Text::Balanced.

Abigail

Replies are listed 'Best First'.
Re: Re: [regex] matching Perl quoted strings
by Jaap (Curate) on Mar 16, 2004 at 15:52 UTC
    Hmmmzzz good point.
    The problem is that i really want to do it with a single regex because of the current flow of the program.
      The problem is that I really want to do it with a single regex because of the current flow of the program.

      Then rework the current flow of the program. A single regex is not the tool you need. Text::Balanced is. Have you read the docs for Text::Balanced yet? It may be that you don't have to redesign your program all that much to use it.

      Perhaps you could maintain the current flow if you wrap the dirty-work done by Text::Balanced in a subroutine.


      Dave

      Well, I'm not going to claim it's impossible to do with a regexp. It certainly is. But I don't have time to work out the details right now, and, considering there's a module doing what you want to do, I don't have any initiative to spend time on it.

      Abigail