I would really like to use \w but it also matches underscores so I'm going with [A-Za-z] which feels unnecessarily verbose and America centric. Is there a better way to do this? Something like [\w^_] (I doubt I got that syntax right)?
Most characters, including all letters ( a-z and A-Z ) and digits ( 0-9 ), match itself. For example, the regex x matches substring "x" ; z matches "z" ; and 9 matches "9" . Non-alphanumeric characters without special meaning in regex also matches itself. For example, = matches "=" ; @ matches "@" .
In order to verify that the string only contains letters, numbers, underscores and dashes, we can use the following regex: "^[A-Za-z0-9_-]*$".
To get a string contains only letters (both uppercase or lowercase) we use a regular expression (/^[A-Za-z]+$/) which allows only letters.
[A-Za-z] will match all the alphabets (both lowercase and uppercase).
Perhaps you mean /[[:alpha:]]/
? See perlre for the discussion of POSIX character classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With