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!

Pattern matching

Status
Not open for further replies.

BStopp

Programmer
Dec 29, 2003
29
US
Is there a simple way to pattern match for only those characters found on a standard US keyboard? Or must i type out each specific key (aside from the \w\s ones obviously).

I tried to use \p{IsASCII} but got back a very weird error message. Which, at this time i can not put into this post.

If i have to type out the characters individually, which ones must be escaped if placed into a set ie: []

Code:
if ($_ =~ /[^\s\w`~!@#\%^&\*\(\)-+=\{\}\[\]\|\\;:'"\?\/><.,]+/)
{
 Do something
}

Would that be the correct way to pattern match for standard keys or is there a simpler way. Also, am i escaping the correct characters or too many? (And yes, what I am really trying to do is find something that is not on a standard US keyboard.)

B
 
if a set of characters exists that are american, there is a commonality with european because they are based on the latin alphabet.

What was the error msg you got, just for kicks ...

The more info you give us, the more we can help

--Paul

Nancy Griffith - songstress extraordinaire,
and composer of the snipers anthem "From a distance ...
 
From perlretut:
The special characters
for a character class are "-]\^$". "]" is special because it denotes the
end of a character class. "$" is special because it denotes a scalar
variable. "\" is special because it is used in escape sequences ...
See that reference for more on char classes.



 
PaulTEG,
Here's the error message I get when i try to use \P{IsASCII} in a regular expression and compare it to the character: ÿÿ

Malformed UTF-8 character (byte 0xff) in pattern match (m//) at ./por_auto_loader.pl line 727, <GEN2> line 22235.

Mikevh, where did you find that quote at?

B
 
perldoc perlretut and search for "special".

If you're not familiar with the perldoc program, try perldoc perldoc at a command prompt.

Or go to and search for perlretut.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top