Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex for a-z, 0-9, . and -

Tags:

regex

Can someone tell me what the syntax for a regex would be that would only allow the following characters:

  • a-z (lower case only)
  • 0-9
  • period, dash, underscore

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

like image 215
Justin Avatar asked Nov 16 '09 19:11

Justin


People also ask

What is the regular expression for identifiers with AZ and 0 9 }?

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 "@" .

What is AZ in regex?

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.

Which Python regular expression method should be used to match any character in Arizona 0 9 or <UNK>?

Python Regex Metacharacters[0-9] matches any single decimal digit character—any character between '0' and '9' , inclusive.

What is regex class 9?

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.


1 Answers

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 String
like image 78
notnoop Avatar answered Oct 12 '22 22:10

notnoop