Welcome to the Monastery | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I agree with others that this looks like a Text::CSV problem (and also that your various problem statements are rather vague). However, in a general regex parsing (and regexes are often not the best approach to parsing) situation, my approach tends to be something like Once you know a string is valid, it's often quite easy to strip out sub-strings of interest. Oh, you say the separator pattern should include possible spaces? Then my $sep = qr{ \s* , \s* }xms; Oh, the "symbol" may be more than a single character and must also exclude spaces? Then my $sym = qr{ [^,\s]+ }xms; And so on. Separately defining $sym and $sep makes them easy to change and makes any change propagate throughout the code as necessary (DRY). And yes, test all this stuff! (Test::More and friends.) Update: Here's another approach to regex (again, maybe not the best option) parsing. It combines validation and extraction into a single regex, but the regex is significantly more complex and probably a bit slower. It also needs Perl version 5.10+ for the \K operator. (Testing, testing...) Give a man a fish: <%-{-{-{-< In reply to Re: check if string is valid with special cases (updated)
by AnomalousMonk
|
|