G'day sp4rperl,

Welcome to the Monastery.

I see tybalt89 has provided a fix for your specific problem and Athanasius has provided an explanation of that fix along with some additional information.

As a general rule for matching between delimiters, consider simply finding the start delimiter and then matching everything which follows that isn't the end delimiter. So, your captures would look like ([^"]*). I find this:

Here's some quick examples showing same/different delimiter pairs matching some/no enclosed text:

$ perl -E 'my ($s, $e) = qw{" "}; q{a"b"c} =~ /$s([^$e]*)/; say "|$1|" +' |b| $ perl -E 'my ($s, $e) = qw{" "}; q{a""c} =~ /$s([^$e]*)/; say "|$1|"' || $ perl -E 'my ($s, $e) = qw{< >}; q{a<b>c} =~ /$s([^$e]*)/; say "|$1|" +' |b| $ perl -E 'my ($s, $e) = qw{< >}; q{a<>c} =~ /$s([^$e]*)/; say "|$1|"' ||

Here's a few more examples, with embedded newlines, showing:

  1. ([^"]*) capturing text as is.
  2. (.*?) capturing nothing as is.
  3. (.*?) capturing text when the 's' modifier is added.
$ perl -E 'my ($s, $e) = qw{" "}; qq{a"b\n"c} =~ /$s([^$e]*)/; say "|$ +1|"' |b | $ perl -E 'my ($s, $e) = qw{" "}; qq{a"b\n"c} =~ /$s(.*?)$e/; say "|$1 +|"' || $ perl -E 'my ($s, $e) = qw{" "}; qq{a"b\n"c} =~ /$s(.*?)$e/s; say "|$ +1|"' |b |

When dealing with data where the enclosed text may include an escaped delimiter (e.g. "abc\"xyz") neither the (.*?) nor the ([^"]*) will work (for that example, both will capture 'abc\'). In these cases, you'll need a somewhat more complex regular expression: see perlre: Quantifiers and search for 'the typical "match a double-quoted string" problem'. [Note: You won't have this issue with HTML.]

— Ken


In reply to Re: Pattern matching and deriving the data between the "(double quotes) in HTML tag by kcott
in thread Pattern matching and deriving the data between the "(double quotes) in HTML tag by sp4rperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.