Example
Description
Below here you will see 2 examples:
- The pattern is a{3,5}b, this means that the text 'aaab' matches this pattern and the text 'aaaaaab' doesn't match pattern.
- The pattern is (test){1,2}. The text 'test' matches the pattern and the text 'testtest' also matches this pattern.
Examples of frequently used regular expressions
Zip Code
Description
A Dutch Zip Code is displayed by a series of 4 numbers and 2 letters. These letters and numbers are separated by a space. The first letter of a Dutch Zip Code has to be a number between 1 and 9. These requirements are translated in the regular expression mentioned below.
Regular Expression
^[1-9]{1}\d{3}[]?[a-z|A-Z]{2}$
Date
Description
There are many ways to describe the format of a date. An example of a date format is using 2 numbers for the day, separation mark (-), 2 numbers for the month, separation mark (-) and 4 numbers for the year. This example can be translated in the next regular expression.
Regular Expression
^(\d{1,2})-(\d{1,2})-(\d{4})$
Amount according to the Dutch notation
Description
There are many ways to describe the format of an amount. According to the Dutch notation it is common that it is allowed to use 0, 1 or 2 decimals. For the decimal separator a comma (,) has to be used, and for the thousands separator a dot (.) has to be used. Theze requirements lead to the next regular expression.
Regular Expression
^(\d{1,3}\.?(\d{3}\.?)*\d{3}(,\d{1,2})?|\d{1,3}(,\d{1,2})?)$
Amount according to the English notation
Description
There are many ways to describe the format of an amount. According to the English notation it is common that it is allowed to use 0, 1 or 2 decimals. For the decimal separator a dot (.) has to be used, and for the thousands separator a comma (,) has to be used. Theze requirements lead to the next regular expression.
Regular Expression
^(\d{1,3},?(\d{3},?)*\d{3}(\.\d{1,2})?|\d{1,3}(\.\d{1,2})?)$
Percentage
Description
The expression has to describe a percentage between 0% and 100% with a maximum of 2 decimals. For the decimal separator you may use a dot (.) or a comma (,).
Regular Expression
^100$|^\d{1,2}$|^\d{1,2}[.,]{1}\d{1,2}$
Password
Description
For passwords is very common to use a regular expression. This means that the password must match certain requirements. As example, these requirements could be the amount of characters in the password and the different kind of symbols (uppercase, lowercase, numbers) in the password.
Regular Expression
Suppose a password has the next requirements:
- A password must contain at least 10 characters;
- A password must contain at least 1 lowercase;
- A password must contain at least 1 uppercase;
- A password must contain at least 1 number;
- A password must contain at least 1 symbol out of the next collection {@,#,$,%,^,&,+,=};