Regex for az, 0-9 ,. and -

Can someone tell me which syntax for the regular expression will consist only of the following characters:

  • az (lowercase only)
  • 0-9
  • period, dash, underline

In addition, the string must begin with a lowercase letter (az) and cannot contain spaces or other characters than those listed above.

Thanks in advance for your help, Justin

+6
regex
source share
3 answers

You can do: "^[az][-a-z0-9\._]*$"

Here is a breakdown

  • ^ start of line
  • [az] 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 line
+10
source share
 [-._a-z0-9] 

or

 [-.[:lower:][:digit:]] 

or...

depends on which version of regular expressions you are striving for.

+2
source share
 ^[az][a-z0-9._\s-]* 
0
source share

All Articles