in reply to Captured single quote results in captured phantom quote

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:  <%-{-{-{-<

Replies are listed 'Best First'.
Re^2: Captured single quote results in captured phantom quote
by choroba (Cardinal) on Aug 25, 2016 at 07:40 UTC
    Getting exactly the same output with 5.20.1 on Linux.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^2: Captured single quote results in captured phantom quote
by Ach (Initiate) on Aug 25, 2016 at 13:35 UTC
    Sorry, I realized almost immediately that the space would have broken the examples, so I changed it. I'll keep the etiquette in mind next time.
      Sorry, ... I'll keep the etiquette in mind next time.

      Ok, great, no problem! But I still don't understand your difficulty as expressed in the OP. Does it have anything to do with the point made in sn1987a's reply?


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