tags:

views:

90

answers:

5

Hey guys can you help me with this. I've got this '/[^A-Za-z]/' but cannot figure out the punctuations part.

Gracious!

+1  A: 

/[^A-Za-z]*/ will match everything except letters. You shouldn't need to specify numbers or punctuation.

kurreltheraven
While what you said is true, it doesn't answer the question. See kiamlaluno's answer.
Jamie Wong
Actually for what I'm doing kurrel is right. but this is a mistake in how I asked the question and in my own code execution. - 2 for me, my apologies. My original regex actually works as needed.
atwellpub
kiamlaluno's second version is more flexible with respect to extra characters for sure, but if you're using the regex in say an if-statement to match what you don't want, you're going to be looking for negatives instead of positives.
kurreltheraven
+3  A: 

The regular expression you are using doesn't allow letters; it's the opposite of what you are reported in the title.

/[a-z]/i is enough, if you want to accept only letters. If you want to allow letters like à, è, or ç, then you should expand the regular expression; /[\p{L}]/ui should work with all the Unicode letters.

kiamlaluno
A: 

Inside of a character class, the ^ means not. So you're looking for not a letter. You want something like

[A-Za-z]+
A: 

you can also use the shorthand \w for a "word character" (alphanumeric plus _). Of course some regex engines may differ on support for this, but if it's PCRE it should work. See here (under heading "escape sequences").

Tim
A: 
#^[^a-z]+$#i

Your code was correct, you just need ^ and $. So it means all character from the beginning to the end doesn't allow outside alphabet. Negative match is preferred than positive match here.

iroel
it means like this: <code>if (preg_match('#^[^a-z]+$#i', $string) echo 'outside alphabet found';</code>
iroel