develooper Front page | perl.beginners | Postings from April 2010

Regex to match a word or phrase (no special character)

Thread Next
From:
Mimi Cafe
Date:
April 21, 2010 14:53
Subject:
Regex to match a word or phrase (no special character)
Message ID:
4bcf73e2.5cebd80a.4ee5.ffffc2e7@mx.google.com
I am trying to match words or complete phrase (excluding special characters)
like:

 

1.	Tom 
2.	Tom and Jerry 
3.	Audio A4 Quattro 

 

I need to ensure users cannot feed my program with special characters so I
tried this below, but it doesn't match correctly.

 

 

$string =~ s/\$%\?\^!\+\@'\\|`\?#~=\*><"//g;

    .

if ($keyword !~ /^([A-Za-z0-9]+)\s?\1*$/){

 

        print "Invalid Keyword. Please check and try again\n";

 

 }

 

My pattern worked at this point, but I modified it over and over again an
now this doesn't work at all.

 

Mimi

 


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About