Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: check if string is valid with special cases

by Veltro (Beadle)
on May 15, 2018 at 15:03 UTC ( #1214561=note: print w/replies, xml ) Need Help??


in reply to check if string is valid with special cases

Or you craft the whole thing yourself.

6 values, 5 commas, strings allowed "", no spaces in values, but spaces between "" allowed, no spaces between comma's...

my $str = '"x,y, z",b,"c",d,e,f' ; my $regex = qr{(?|(?>\"([^\s\"]+|(?:[\s]*[^\s\"]+)+)[\s]*\")|([^,\s\"] +))} ; if ( $str =~ /^$regex,$regex,$regex,$regex,$regex,$regex$/ ) { print "1= $1\n" ; print "2= $2\n" ; print "3= $3\n" ; print "4= $4\n" ; print "5= $5\n" ; print "6= $6\n" ; } else { print "No match 1\n" ; } __END__ 1= x,y, z 2= b 3= c 4= d 5= e 6= f

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214561]
help
Chatterbox?
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-05-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?