Sep 22, 2005 #1 jouell MIS Nov 19, 2002 304 US Is this the best perl code to match a string that can only have letters, numbers,spaces,dash, forward slash, backslash, and pipe (|)? #!/usr/bin/perl -w $command=shift; unless ($command=~ /^([-\w.\s\/\\\|]+)$/) { print "Security error.\n"; exit (1); }
Is this the best perl code to match a string that can only have letters, numbers,spaces,dash, forward slash, backslash, and pipe (|)? #!/usr/bin/perl -w $command=shift; unless ($command=~ /^([-\w.\s\/\\\|]+)$/) { print "Security error.\n"; exit (1); }
Sep 22, 2005 #2 TrojanWarBlade Programmer Apr 13, 2005 1,783 GB yep, Looks ok to me. Trojan. Upvote 0 Downvote
Sep 22, 2005 #3 regex7 Programmer Feb 17, 2005 11 DE It also allows underscore (_) as this is included in \w. Upvote 0 Downvote
Sep 22, 2005 #4 KevinADC Technical User Jan 21, 2005 5,070 US there may also be no need for the parenthesis in that regexp since you appear to not be capturing the pattern in memory. Upvote 0 Downvote
there may also be no need for the parenthesis in that regexp since you appear to not be capturing the pattern in memory.
Sep 22, 2005 Thread starter #5 jouell MIS Nov 19, 2002 304 US regex7: Nice catch on the underscore! Didn't think of that. Thanks! kevin: Also thanks for the tip regarding the parens! trojan: thanks for your eyes! Upvote 0 Downvote
regex7: Nice catch on the underscore! Didn't think of that. Thanks! kevin: Also thanks for the tip regarding the parens! trojan: thanks for your eyes!
Sep 22, 2005 #6 TrojanWarBlade Programmer Apr 13, 2005 1,783 GB Looks like my eyes are more tired than I thought! ;-) Glad you got the feedback you wanted. Trojan. Upvote 0 Downvote