Could somebody help me create a regex that matches only characters?
Thanks in advance!
Could somebody help me create a regex that matches only characters?
Thanks in advance!
Use a character set: [a-zA-Z]
matches one letter from A–Z in lowercase and uppercase. [a-zA-Z]+
matches one or more letters and ^[a-zA-Z]+$
matches only strings that consist of one or more letters only (^
and $
mark the begin and end of a string respectively).
If you want to match other letters than A–Z, you can either add them to the character set: [a-zA-ZäöüßÄÖÜ]
. Or you use predefined character classes like the Unicode character property class \p{L}
that describes the Unicode characters that are letters.
\p{L}
matches anything that is a Unicode letter if you're interested in alphabets beyond the Latin one
/[a-zA-Z]+/
Super simple example. Regular expressions are extremely easy to find online.
Depending on your meaning of "character":
[\w]* matches whatever the regex engine thinks is a word character 0 or more times