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"; }
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 | |
|
Re^2: Captured single quote results in captured phantom quote
by Ach (Initiate) on Aug 25, 2016 at 13:35 UTC | |
by AnomalousMonk (Archbishop) on Aug 25, 2016 at 13:49 UTC |