Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

regex for single lower case word

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

like image 763
abarr Avatar asked Aug 08 '10 11:08

abarr


People also ask

What does ?= * Mean in regex?

?= 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).

What does \b represent in regex?

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.

What is a za z regex?

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.

What is capital S in regex?

The \s metacharacter matches whitespace characters.


2 Answers

The character class [a-z] describes one single character of the alphabet of lowercase letters az. 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.

like image 55
Gumbo Avatar answered Oct 19 '22 06:10

Gumbo


^[a-z]+$ Will find one and only one lower-case word, with no spaces before or after the word.

like image 32
Merlyn Morgan-Graham Avatar answered Oct 19 '22 07:10

Merlyn Morgan-Graham