in reply to Regexp issue

Eily is right, you should not have the braced term within the character class.

m/^"{1}[^"{1}]/ # ^^^ ^^^-This is wrong # | # This is unnecessary

If you are testing the same thing (here that a string matches a certain regex) more than once, don't write the code out more than once as (a) you might not type it the same in error and (b) if you make changes you need to do them twice. This is called DRY in the jargon.

Taking both of these into account, and assuming you just want to match a leading double-quote followed by something other than a double-quote, here's an altered version of your code showing both date strings matching:

use strict; use warnings; use feature 'say'; my @strings = ('"18/02/2018"', '"28/02/2018"'); for (@strings) { say if /^"[^"]/; }

You can of course expand on this by putting other values into @strings and see if they match or not. If it gets any fancier, try turning it into a test instead with Test::More.

Replies are listed 'Best First'.
Re^2: Regexp issue
by QuasarD (Novice) on Feb 22, 2018 at 15:52 UTC

    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

      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"); }