Regex Tester

Spread the love

{{ errors[0] }}


{{ errors[0] }}

Matches

{{ text }}

JavaScript Regex Cheat Sheet

  • /hello/ – looks for the string between the forward slashes (case-sensitive)

  • /hello/i – looks for the string between the forward slashes (case-insensitive)

  • /hello/g – looks for multiple occurrences of string between the forward slashes

  • /h.llo/ – the "." matches any one character other than a new line character

  • /h.llo/ – the "" matches any character(s) zero or more times

  • /\d/ – matches any digit

  • /\D/ – matches any non-digit

  • /\w/ – matches any word character (a-z, A-Z, 0-9, _)

  • /\W/ – matches any non-word character

  • /\s/ – matches any white space character (\r (carriage return),\n (new line), \t (tab), \f (form feed))

  • /\S/ – matches any non-white space character

  • /[abc]/ – matches any character in square brackets

  • /[ck]atherine/ – matches catherine or katherine

  • /[^abc]/ – matches anything except the characters in square brackets

  • /[a-z]/ – matches all lowercase letters

  • /[A-Z]/ – matches all uppercase letters

  • /[e-l]/ – matches lowercase letters e to l (inclusive)

  • /[F-P]/ – matches all uppercase letters F to P (inclusive)

  • /[0-9]/ – matches all digits

  • /[5-9]/ – matches any digit from 5 to 9 (inclusive)

  • /[a-zA-Z]/ – matches all lowercase and uppercase letters

  • /[^a-zA-Z]/ – matches non-letters

  • /(hello){4}/ – matches "hellohellohellohello"

  • /hello{3}/ – matches "hellooo" and "helloooo" but not "helloo"

  • /\d{3}/ – matches 3 digits ("312", "122", "111", "12312321" but not "12")

  • /\d{3,5}/ – matches digits that occur between 3 and 5 times (inclusive)

  • /\d{3,}/ – matches digits that occur at least 3 times

  • /ab*c/ – matches zero or more repetitions of "b" (matches "abc", "abbbbc", "ac")

  • /ab+c/ – matches one or more repetitions of "b" (matches "abc", "abbbbc", but not "ac")

  • /^[A-Z]\w*/ – matches "H", "Hello", but not "hey"

  • /\w*s$/ – matches "cats", "dogs", "avocados", but not "javascript"

  • /\bmeow\b/ – matches "hey meow lol", "hey:meow:lol", but not "heymeow lol"

  • /it is (ice )?cold outside/ – matches "it is ice cold outside" and "it is cold outside"

  • /it is (?:ice )?cold outside/ – same as above except it is a non-capturing group

  • /do (cats) like fish \1/ – matches "do cats like fish cats"

  • /do (cats) like (fish)? do \2 \1 like you?/ – matches "do cats like fish? do fish cats like you?"

  • /i like (apple|orange|grape)./ – matches "i like apple.", "i like orange.", and "i like grape."

  • /(\2train|(choo))+/ – matches "choo", "choochoo", "chootrain", choochootrain", but not "train"

  • b(?=a)/ – positive lookahead… matches the "z" before the "a" in boba" but not the first "b"

  • /b(?!a)/ – negative lookahead… matches the first "b" but not the "b" before the "a"

  • /(?<=[aeiou])\w/ – positive lookbehind… matches any word character that is preceded by a vowel

  • /(?<![aeiou])\w/ – negative lookbehind… matches any word character that is not preceded by a vowel