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!

NOT "!" or " "

Status
Not open for further replies.

CJason

Programmer
Oct 13, 2004
223
US
How do you specify NOT "!" or " " (blank)? I know I could write these separately, like:

!/\!/ && !/ /

But, I'd like to use the [] capabilities (if that's actually how you would do this). For example, this would MATCH A-Z (as you all probably know):
/[A-Z]/

Can this form be used for NOT? Thanks in advance!!!
 
Code:
my $string = " ";
if($string !~ /[\! ]/) {
  # Isn't a '!' or ' '
} else {
  # Is
}
 
No need to escape the '!' character in the regexp.
 
You could also use the pipe symbol as well...i.e.:
Code:
my $string = " ";
if($string !~ /!| ) {
  # Isn't a '!' or ' '
} else {
  # Is
}
Sorry for stealing your code, Nebbish, was a bit short of time !



Rob Waite
 
waiterm, you're missing the closing / on the regex. Should be /!| /.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top