G'day ovedpo15,
You can do your validation with this condition:
$string =~ y/,/,/ == -1 + grep length y/ //dr, split /,/, $string
I ran these tests based on the ever-shifting goal posts throughout this thread. :-)
$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -E' $ perle 'my $x = "a,b,c"; say +($x =~ y/,/,/ == -1 + grep length y/ // +dr, split /,/, $x) ? "Y" : "N"' Y $ perle 'my $x = "a,b ,c"; say +($x =~ y/,/,/ == -1 + grep length y/ / +/dr, split /,/, $x) ? "Y" : "N"' Y $ perle 'my $x = "a, ,c"; say +($x =~ y/,/,/ == -1 + grep length y/ / +/dr, split /,/, $x) ? "Y" : "N"' N $ perle 'my $x = "a, ,c"; say +($x =~ y/,/,/ == -1 + grep length y/ // +dr, split /,/, $x) ? "Y" : "N"' N $ perle 'my $x = "a,,c"; say +($x =~ y/,/,/ == -1 + grep length y/ //d +r, split /,/, $x) ? "Y" : "N"' N
— Ken
In reply to Re: check if string is valid with special cases
by kcott
in thread check if string is valid with special cases
by ovedpo15
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |