faqts : Computers : Programming : Languages : Perl : Common Problems : Pattern Matching

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 7 people (29%) answered Yes
Recently 2 of 7 people (29%) answered Yes

Entry

How can I make a regex return true when it doesn't match a string?

Jun 16th, 2001 05:57
Per M Knutsen,


A common beginner's error is to pre-cede the variable with an 
exclamation mark, as this:
if (!$string =~ m/^\.+&/ ) {
   ...
}
when actually what should be done is to replace the equal sign with the 
exclamation mark, thus:
if ($string !~ m/^\.+&/ ) {
   ...
}