in reply to Regular expression for combination of data
I'm not sure from your question what exactly you're trying to accomplish. Here are a couple of options...
my $valid_chars = 'CETLMNPA'; if ($CD =~ m/^[$valid_chars](?:,[$valid_chars])*$/) { print "Valid!" } else { die "Invalid!" }
Let's break down that regular expression:
m/ ^[$valid_chars] #the string must start with one of the valid char +s (?: #start group, but don't capture! , #could have a comma [$valid_chars] #and another valid char )* #and that comma+valid char could repeat 0 or more + times $ #until the end of the string /x #this is here to allow me to use all these commen +ts
For example, if I want to know at various points in code if a given flag is set:
my %config = map { $_ => 1 } split(',', $CD); ## later on... if ( $config{L} ) { print "L was set!" }
You might use the validation from above in combination with this.
|
---|