Skip to main content
Skip table of contents

List of Regular Expressions

Working with our application you can use the following regular expressions:

  • General Expressions 

  • Maximum Quantifiers 

  • Alternative and Grouping 

  • Special notations with \

  • Examples

  • Additional examples of complex expressions

General Expressions 

a

matches any value containing the letter a

apple, and, canal

^

matches the beginning of a string.

The expression ^A stands for the 'A' in "Anthony goes to Spain," but does not stand for it in "Susan goes to Africa"

$

matches the end of a string.

The expression t$ stands for the 't' in "seat," but does not stand for it in "teacher"

.

matches any single character.

For example, .n will correspond to 'an' and 'on', but not to 'navy'.

[...]

matches any of the characters in the sequence.

The expression [abd] allows entering words containing the letters in brackets: doll, bath, apricot.
The expression [1-9] allows entering any number from 1 to 9.
The '-' character is treated as a literal character if it is the last or the first character within the brackets, or if it follows a backslash: [abc-], [-abc], or [a\-bc].

[^...]

matches any character except those in the sequence.

If you use expression [^abc] your respondents will not be allowed to input anything that contains letters a, b or c.

Maximum Quantifiers 

{m,n}

matches preceding character at least m, but not more than n times

For example, the expression a{1,3} means that you can enter words containing from 1 to 3 letters 'a'

{m,}

matches preceding character m or more times

The expression a{2,} allows entering words containing 2 or more letters 'a'

{,n}

matches preceding character from 0 to n times

The expression a{,2} allows you to enter words containing from 0 to 2 letters 'a'

*

matches preceding character 0 or more times

The expression bo* allows you to input words containing only one letter 'b' and 0 or more letters 'o'

+

matches preceding character 1 or more times

The expression a+ allows entering words containing 1 or more letters 'a'

?

matches preceding character 0 or 1 times

Using the expression e? you can input words containing 0 or 1 letter 'e'

Alternative and Grouping 

|

alternative

The expression green|red means that you can input either 'green' or 'red'

( )

grouping

The expression (ca)* means that * refers to all characters in brackets and you can input words containing 0 or more letters 'c' and 'a'

Special notations with \

\

toggles off the interpretation of metacharacters and converts the following alphacharacters (w,d,s) in metacharacters.

For example, * is a special character that means 0 or more occurrences of the preceding character should be specified; for example, a* means match 0 or more a's. To match * literally, precede it with a backslash; for example, a\* matches 'a*'.

\w

matches any single character classified as a "word" character: a letter or a number

The expression \w allows entering a letter or a number

\d

matches any digit character, equivalent to [0-9]

The expression \d allows entering a number from 0 to 9.

\s

matches any white space character (space, tab, new line, form feed)

The expression \s\w* allows to input only one white space and after it 0 or more letters or numbers.

\W

matches any non-"word" character

The expression \W means that you can enter everything except letters and numbers.

\D

matches any non-digit character

The expression \D allows entering everything except numbers.

\S

matches any non-whitespace character

The expression \S allows to input everything except white spaces.

Examples

^[0-5]?[0-9]$ - this simple expression allows to enter any whole number from 00 to 59. 1-digit numbers from 0 to 9 are allowed as well.

  • ^ - asserts position at the beginning of the string

  • [0-5] - matches a single character in the range between '0' and '5'

  • ? - matches the preceding element 0 or 1 times

  • [0-9] - matches a single character in the range between '0' and '9'

  • $ - asserts position at the end of the string

You can use regular expressions if you need to create a format that will allow users to enter only phone numbers of the following types:

(756)667-7832 or (756) 667 - 7832 ext. 234

In this case the formula will look like \(\d{3}\)\s?\d{3}\s?-\s?\d{4}\s?(\w+\.?\s?\d+)*

  • \(\) stands for brackets, \ is used to interpret () as simple brackets;

  • \d{3} refers to the sequence of three digits (numbers 0 to 9);

  • \d{4} refers to the sequence of four digits (numbers 0 to 9);

  • \s? means that there can be no spaces or only one space;

  • \w+ means that there can be one or more letters;

  • \d+ means that there can be one or more digits (numbers 0 to 9);

  • \.? stands for the dot, \ is used to interpret . as a simple dot and it means that there can be no dots or only one dot;

  • (\w+\.?\s?\d+)* means that the combination of letters and numbers can occur many times or never at all.

Additional examples of complex expressions

^\d+$

Number

Any whole positive number + 0

(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d

Date

Matches a date in mm/dd/yyyy format from between 1900-01-01 and 2099-12-31. '-', '/', '.' can be used as separators.

^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$

Domain name

Example: app.keysurvey.com

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.