Hi i need a regex that matches all instances of any character that is not a-z (space and things like apostrophes need to be selected). Sorry for the noob factor. thanks!
//novice
Hi i need a regex that matches all instances of any character that is not a-z (space and things like apostrophes need to be selected). Sorry for the noob factor. thanks!
//novice
The character class [^a-zA-Z] will match any character that isn't (upper or lowercase) a-z.
I'm sure you can figure out the rest.
Here is regex that will literally match any char that is not a-z. The /g flag indicates a global match which will cover all instances of the match.
/[^a-z]+/g
If you need uppercase letters too, you can either pass the /i flag which indicates case insensitivity:
/[^a-z]+/gi
or include the uppercase chars in character class:
/[^a-zA-Z]+/g
\W will match any non-alphanumeric (a-z, 0-9, and underscore) character.
The following regular expression matches any letter other than [a-z]:
/[^a-z]+/
OK.
With a somewhat sophisticated regex engine (grep will do just fine) this will be quite general:
/[^[:lower:]]+/
(Note the ^!)
The difference between [:lower:] and [a-z] is that the former should be I18N friendly and match e.g. ü, â etc.
For case insensitive matching use [:alpha:], to also include digits use [:alnum:]. [:alnum:] differs from \W in that it doesn't include _ (underscore).
Note that character classes written in this style may be combined as usual (like a-z etc.), e.g. [^[:lower:][:digit:]]+ would match a non-empty string of characters not including any lowercase letters or digits.
If you ever need to create another regex try reading this. Teaching to fish and all that. :)