in reply to Re: Alternation in pattern matches
in thread Alternation in pattern matches

You don't like (")?(?(1)[^"]+|[^"\s]+) ?

Replies are listed 'Best First'.
Re: Re: Re: Alternation in pattern matches
by ambrus (Abbot) on Feb 19, 2004 at 15:36 UTC

    It just won't catch a missing closing qquote, as in TAG:"test of data. However, you can correct that like: my ( $data ) = m/TAG:(")?((?(1)[^"]+|[^"\s]+))(?(1)")/ ? $2 : 'not_def';

      Sorry, was just being overly terse; in full, that would be:
      /TAG:(")?((?(1)[^"]+|[^"\s]+))(?(1)")/ ? $2 : "not_def"
      (I had thought that \1 would work instead of (?(1)")), but it makes sense that it doesn't.)
        Good idea: m/TAG:((")?)((?(2)[^"]+|[^"\s]+))\1/ ? $3 : 'not_def';, that didn't occur to me.