Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matching only certains characters

Status
Not open for further replies.

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);
}
 
It also allows underscore (_) as this is included in \w.
 
there may also be no need for the parenthesis in that regexp since you appear to not be capturing the pattern in memory.
 
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!
 
Looks like my eyes are more tired than I thought!
;-)
Glad you got the feedback you wanted.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top