Can someone tell me what the syntax for a regex would be that would only allow the following characters:
Additionally the string must start with only a lower case letter (a-z) and cannot contain any spaces or other characters than listed above.
Thank you in advance for the help, Justin
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 "@" .
The regular expression [A-Z][a-z]* matches any sequence of letters that starts with an uppercase letter and is followed by zero or more lowercase letters. The special character * after the closing square bracket specifies to match zero or more occurrences of the character set.
Python Regex Metacharacters[0-9] matches any single decimal digit character—any character between '0' and '9' , inclusive.
A regular expression (sometimes called a rational expression) is a sequence of characters that define a search pattern, mainly for use in pattern matching with strings, or string matching, i.e. “find and replace”-like operations.
You can do: "^[a-z][-a-z0-9\._]*$"
Here is the breakdown
^
beginning of line[a-z]
character class for lower values, to match the first letter[-a-z0-9\._]
character class for the rest of the required value*
zero or more for the last class$
end of StringIf 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