How to create a Regular Expression

What is a Regular Expression?

A regular expression (regex) is a sequence of characters that specifies a match pattern in the text. For example, you would like to ensure that your colleagues always use the 24-hour format when submitting the expenses of a past business event. The following regexachieves that:


In this scenario, the user must use the HH:MM time format in the input field to proceed.

ℹ️ Try first using the Generate functionality as explained in the following help article. Use the below examples to improve or adapt the automatically generated Regular Expression to your use case.

When to use a Regular Expression?

You can use a Regular Expression when it is important to validate the collected data. For example:

  • check if the text that was typed in contains the domain of your organization
  • don't allow users to submit empty form fields 
  • enforce a unique format for all the number fields
  • don't allow more than 10 words in a text box.
  • create an age validation (e.g., 18-65)

Ultimately, the goal is to collect correct and useful information for your processes.  

How to use it?

Below there are some simple examples to give you a better understanding of how basic Regular Expressions can be used.

abcabc is allowedonly abc is accepted
Munich|Berlin|HamburgThe user needs to type in Munich or Berlin, or Hamburg to get the result validated."|" is used as "or"
[a-z]A23BCDeFAt least one small letter from a to z needs to be detected in the string
[0-9]1user1The user needs to type in a string that contains at least one number
[0-9]$31231031231...It accepts only strings
[0-9] \$$25$\ is used to escape a special character. In our case, the $ sign. The second $ shows where the string ends
^[A-Z]Userlane or USERlane are allowed. uSerlane or userLANE are not allowedYou need to start the string with a Capital letter. It can contain more capital letters.
.!Userlane#:; is valid"." is a wild card. If used, any character is accepted in the string.
.{3,}At least three characters need to be typed in{3,} means that min 3 characters need to be typed in.
^.{12,20}$Any string between 12 and 20 characters{12,20} means the string must contain between 12 and 20 characters. ^ is used to say where the counting starts, while $ shows when the counting ends.
^[1-9]{1}$|^10$Validate a number from 1 to 10^[1-9]{1}$ tells us the first number is 1 to 9.
| means or
^10$ tells us that also 10 is accepted
^[1-9]?[0-9]{1}$|^100$Validate a number from 1 to 100

The "?" tells us that the preceding character is optional. If it wouldn't be there, then the user would be allowed to type in numbers only from 10 to 100

Now, let's take another look at the example from above:


The first part of the regular expression ^(([01][0-9]|2[0-3]) tells the user that a value between 00 and 19 is needed or between 20 and 23. In the second part of the regular expression, [0-5][0-9]$, a value between 00 and 59 is expected. In that way, only entries in the format of HH:MM are accepted.

Advanced examples

^[-\w]+(?:\W+[-\w]+){1,4}\W*$To proceed, type in 1 to 5 words. 
^.+?@.+?\..+$    It can be used for email validation. The pattern checks if "@" and "." exist.
((1[0-2]|0?[1-9]):([0-5][0-9]) ?([AaPp][Mm]))$        It validates if the following time format HH:MM 12-hour AM/PM is used.
/^[0-9]{5}([- /]?[0-9]{4})?$/Checks if the US Postal code was entered correctly.
^(?!01000|99999)(0[1-9]\d{3}|[1-9]\d{4})$It checks if the entered German Postal Code exists.
^DE[0-9]{20}$It checks if the German IBAN was correctly entered.

ℹ️ If you would like to receive support in creating regular expressions, please don't hesitate to contact us anytime.

User Icon

Thank you! Your comment has been submitted for approval.