I am looking for a regex pattern that ensures the user puts in a single lower case word with only letters of the alphabet. Basically they are picking a subdomain. Thanks in advance
?= is a positive lookahead, a type of zero-width assertion. What it's saying is that the captured match must be followed by whatever is within the parentheses but that part isn't captured. Your example means the match needs to be followed by zero or more characters and then a digit (but again that part isn't captured).
Inside a character range, \b represents the backspace character, for compatibility with Python's string literals. Matches the empty string, but only when it is not at the beginning or end of a word.
Using character sets For example, the regular expression "[ A-Za-z] " specifies to match any single uppercase or lowercase letter. In the character set, a hyphen indicates a range of characters, for example [A-Z] will match any one capital letter. In a character set a ^ character negates the following characters.
The \s metacharacter matches whitespace characters.
The character class [a-z]
describes one single character of the alphabet of lowercase letters a
–z
. If you want if an input does only contain characters of that class, use this:
^[a-z]+$
^
and $
mark the start and end of the string respectively. And the quantifier +
allows one or more repetitions of the preceding expression.
^[a-z]+$ Will find one and only one lower-case word, with no spaces before or after the word.
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