Alphabet used in regular expressions

Name Conventional designation Usage example
Any character * "c"*"t" allows such words as cat, cot, etc.
Letter C C"ot" allows such words as Rot, pot, cot, Dot, mot, etc.
Uppercase letter A A"ot" allows such words as Rot, Cot, Mot, Dot, etc.
Lowercase letter a a"ot" allows such words as rot, cot, mot, dot, etc.
Letter or number X X allows any standalone number or letter.
Number N N"th" allows such words as 5th, 4th, 6th, etc.
String " " "cot"
Or | "pl"("o"|"a")"t" allows words "plot" and "plat".
Character from group [] [tm]"ot" allows words "tot" and "mot".
Character not from group [^] [^t]"ot" allows words "cot", "lot", etc., but does not allow the word "tot".
Space (within group) \s [A\s] allows only the letter A or a space.

Any number of repetitions

(applies to the expression or subexpression on the left)

{-} [AB74]{-} allows any combinations of characters A, B, 7, 4 of any length.
Number of repetitions n {n} N{2}"th" allows such words as 25th, 84th, 11th, etc.
From n to m repetitions {n-m} N{1-3}"th" allows such words as 5th, 84th, 111th, etc.
From 0 to n repetitions {-n} N{-2}"th" allows such words as 84th, 5th, etc.
From n repetitions and more {n-} N{2-}"th" allows such words as 25th, 834th, 311th, 34576th, etc.
Subexpression ()
Hyphen symbol [\-]
Slash symbol [\\]

Examples of regular expressions:

  1. Postal code: [0-9]{6}
    An sample value: "142172"
  2. Zip code (USA): [0-9]{5}("-"[0-9]{4}){-1}
    Sample values: "55416", "33701-4313"
  3. Income: N{4-8}[,]N{2}
    Sample values: "15000,00", "4499,00"
  4. Month in the numerical form: ((|"0")[1-9])|("10")|("11")|("12")
    Sample values: "4", "05", "12"
  5. Fraction: ("-"|)([0-9]{1-})(|(("."|",")([0-9]{1-})))
    Sample values: "1234,567", "0.99", "100,0", "-345.6788903"
  6. E-mail: [A-Za-z0-9_]{1-}(("."|"-")[A-Za-z0-9_]{1-}){-3}"@"[A-Za-z0-9_]{1-}(("."|"-")[A-Za-z0-9_]{1-}){-4}"."([A-Za-z]{2-4}|"asia"|"museum"|"travel"|"example"|"localhost")
    Sample values: "", "", ""

02.03.2021 8:10:41

Please leave your feedback about this article