Can someone elaborate the following regular expression:
/^[a-z]{1}[a-z0-9_]{3,13}$/
and also give some sample strings that satisfy this regular expression?
Can someone elaborate the following regular expression:
/^[a-z]{1}[a-z0-9_]{3,13}$/
and also give some sample strings that satisfy this regular expression?
^ anchor asserts that we are at the beginning of the string[a-z]{1} matches one lower-case letter. The {1} is unneeded.[a-z0-9_]{3,13} matches 3 to 13 chars. In case-insensitive mode, in many engines it could be replaced by \w{3,13}$ anchor asserts that we are at the end of the stringSample Matches
abcd
a_000
a_blue_tree
See demo.
General Answers to "What Does this Regex Mean?
Explanation: /^[a-z]{1}[a-z0-9_]{3,13}$/
^ - Asserts the start of a string
[a-z]{1} Matches exactly one character from a-z.
[a-z0-9_]{3,13} Matches any character from a-z or 0-9 but the length range must between 3 to 13.
$ End
NODE EXPLANATION
^ the beginning of the string
[a-z]{1} any character of: 'a' to 'z' (1 times)
[a-z0-9_]{3,13} any character of: 'a' to 'z', '0' to '9',
'_' (between 3 and 13 times (matching the
most amount possible))
$ before an optional \n, and the end of the
string
It means:
Start(^) with one ({1}) lowercase character([a-z]), then proceed with at least three ({3,) but with a maximum of 13 (13}) characters from the set of lowercase characters, underline and numbers([a-z0-9_]). After that the end of line is expected ($).
a000 satisfies the condition
It matches a string starting with a-z followed by 3 to 13 characters from the character set a-z, 0-9 or _.
There are a number of online tools that will explain/elaborate the meaning of a regular expression as well as test them.
Assert position at the beginning of the string «^»
Match a single character in the range between “a” and “z” «[a-z]{1}»
Exactly 1 times «{1}»
Match a single character present in the list below «[a-z0-9_]{3,13}»
Between 3 and 13 times, as many times as possible, giving back as needed (greedy) «{3,13}»
A character in the range between “a” and “z” «a-z»
A character in the range between “0” and “9” «0-9»
The character “_” «_»
Assert position at the end of the string (or before the line break at the end of the string, if any) «$»
Generated using RegexBuddy