in reply to
parsing file/regex question
Thanks for all of the help on this so far...I took the suggestions and I expanded the sample program to see if that makes a difference...
I am hoping to get this as data driven as possible to reduce errors (especially when I cut-n-paste ;-)
I am looking to process some lines in a file and validate text (I am not yet using Taint, but will at some point ;)
My problem is how to validate \n or \t, as sometimes it is allowed in the text field.
The following code should work, but I just want to make sure that the s/\\t/\t/g; (and the other ones that I might need) are the best way to go)
Thanks again for any help!!!!
$PRE = '\[\s*';
$VALID1 = '[-a-zA-Z0-9_.* \t\n]';
$VALID2 = '[-a-z0-9_.*\n]';
$VALID3 = '[a-zA-Z]';
$VALID4 = '[-a-zA-Z0-9]';
$PST = '\s*\]';
while (<DATA>)
{
s/\\n/\n/g; #Are these harmless if
s/\\t/\t/g; #not needed???
print "yep\n" if m/$PRE($VALID1+)$PST
$PRE($VALID2+)$PST
$PRE($VALID3+)$PST
$PRE($VALID4+)$PST
/ox;
}
__DATA__
[TEST \n DATA] [ TEST DATA ] [ 2345423 ] [ TEST DATA ]\n
[TEST \n DATA] [ TEST DATA ] [ 2345423 ] [ TEST\tDATA ]\n
[TEST \n DATA] [ TEST DATA ] [ 2345423 ] [ TEST DATA ]\n