NOTE: The original OP had
    DB<1> $line = "\"quoted text\" \cM\cJ"
(which does not match at all) in place of the current
    DB<1> $line = "\"quoted-text\" \cM\cJ"
(which matches as I would expect). Please be aware that silent updates like this can be very annoying. Please see How do I change/delete my post? for site etiquette and protocol regarding editing posts.

... the wrong result for array element 2.

I'm not sure what you mean by this: can you please clarify? Old and new strings match (update: and capture) as I expect. (Update: But I can only run Perl version 5.14.4 at most. (Further Update: I get the same results from my script running under 5.10.1, both Strawberry.))

use warnings; use strict; use Data::Dump qw(pp); print "perl version $] \n\n"; for my $line ( "\"quoted text\" \cM\cJ", "\"quoted_text\" \cM\cJ", "\"quoted-text\" + \cM\cJ" ) { print 'line: ', pp($line), "\n"; my @ra; @ra = $line =~ m/^(\s*)((?'quote'"?)[^\s"]*\g{quote})\s+(\[[^\]]*\]| +)\s*$/; print 'rx 1: ', pp(\@ra), "\n"; @ra = $line =~ m/^(\s*)((?'quote'"?)[^\s"]*")\s+(\[[^\]]*\]|)\s*$/; print 'rx 2: ', pp(\@ra), "\n"; @ra = $line =~ m/^(\s*)(("?)[^\s"]*")\s+(\[[^\]]*\]|)\s*$/; print 'rx 3: ', pp(\@ra), "\n"; @ra = $line =~ m/^(\s*)("?[^\s"]*")\s+(\[[^\]]*\]|)\s*$/; print 'rx 4: ', pp(\@ra), "\n"; }
Output:
c:\@Work\Perl\monks\Ach>perl regex_problem_1.pl perl version 5.014004 line: "\"quoted text\" \r\n" rx 1: [] rx 2: [] rx 3: [] rx 4: [] line: "\"quoted_text\" \r\n" rx 1: ["", "\"quoted_text\"", "\"", ""] rx 2: ["", "\"quoted_text\"", "\"", ""] rx 3: ["", "\"quoted_text\"", "\"", ""] rx 4: ["", "\"quoted_text\"", ""] line: "\"quoted-text\" \r\n" rx 1: ["", "\"quoted-text\"", "\"", ""] rx 2: ["", "\"quoted-text\"", "\"", ""] rx 3: ["", "\"quoted-text\"", "\"", ""] rx 4: ["", "\"quoted-text\"", ""]


Give a man a fish:  <%-{-{-{-<


In reply to Re: Captured single quote results in captured phantom quote by AnomalousMonk
in thread Captured single quote results in captured phantom quote by Ach

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.