Reputation: 6010
Hey guys can you help me with this. I've got this '/[^A-Za-z]/' but cannot figure out the punctuations part.
Gracious!
Upvotes: 0
Views: 5310
Reputation: 1798
#^[^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.
Upvotes: 2
Reputation: 3182
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").
Upvotes: 0
Reputation: 29669
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.
Upvotes: 4
Reputation: 892
Inside of a character class, the ^ means not. So you're looking for not a letter. You want something like
[A-Za-z]+
Upvotes: 0
Reputation: 116
/[^A-Za-z]*/ will match everything except letters. You shouldn't need to specify numbers or punctuation.
Upvotes: 1