in reply to Re: Regexp issue
in thread Regexp issue

assuming you just want to match a leading double-quote followed by something other than a double-quote

I forgot to mention that i have to parse CSV rows, so i have to match a leading double-quote followed by EXACTLY something other than a double-quote, because a third double-quote will be escaped by the previous one:

"18/02/2018" <- in this case the record is 18/02/2018

""18/02/2018" <- in this case the record is invalid

"""18/02/2018" <- in this case the record is "18/02/2018

Replies are listed 'Best First'.
Re^3: Regexp issue
by hippo (Archbishop) on Feb 22, 2018 at 16:10 UTC

    Previous advice from others about using a module notwithstanding, this additional requirement puts it well into "If it gets any fancier" territory. Here, therefore, is the test:

    use strict; use warnings; use Test::More; my @good = ( '"18/02/2018"', '"""18/02/2018"' ); my @bad = ( '""18/02/2018"' ); my $re = qr/^"("")?[^"]/; plan tests => @good + @bad; for my $str (@good) { like ($str, $re, "$str matched"); } for my $str (@bad) { unlike ($str, $re, "$str not matched"); }