Topic: How to use regular expressions  (Read 8484 times)

ConfTool Pro has several functions for which you can use “regular expressions” to check the data entered by users. You can use them to verify registration codes for participant groups, registration codes for single events/items and for submission codes for conference tracks / submission types.

We also provide this information in German

This page gives you a short overview on how to define these regular expressions.
Although regular expressions are powerful and can be very complex, for the use in ConfTool these codes are in most cases easily created.

Control Characters
Many symbols like ^, $, /, +, ?, [,  ] and * are control characters (also called meta characters) and have a special function. If you want to use them in your code, you have to add the escape character “\” before the symbol, otherwise the system will try to process the symbol as a control character. Maybe just avoid them when you define your codes and only use regular characters from A to Z and 0 to 9, and you will not experience any problems.

Basic use of Control Characters
If you simply enter a text into the code field (where you define the regular expression), all strings will be accepted that include this code. Please note that the codes are case sensitive, so “a” and “A” are two different characters.

If you want to make sure that the string starts with your code, add the symbol “^” to the start.
Example: “^ABC” will accept all strings that start with “ABC”

If you want to make sure that the string ends with your code, add the symbol “$” to the end.
Example: "XYZ$" will accept all strings that end with "XYZ"

So if you want to allow only strings that exactly match your code, add “^” to the start and “$” to the end.
Example: “^SECRET$” will only accept the string “SECRET”

Wildcards
The symbol “.” stands for any single character. If you use it in your code, any character the author/participant enters will be accepted.
Example: “AB.YZ” will accept any string with “ABAYZ”, “ABaYZ” or “AB0YZ” and so on.
The code [a-z] stands for any character from a-z, [A-Z] for the capital equivalent and [0-9] for any number. You can also use sub-ranges, like “[a-c]” to accept the characters “a” to “c” only.

Grouping: Sequences of Characters
Use brackets “(“ and “)” to define sequences of characters that belong together. This is especially useful with the use of the codes that express repeated sequences (see below).

The Or Operator
Furthermore, you can use the “|” symbol, that works as an OR operator.
Example: “(ABC|XYZ)” will accept the strings “ABC” or “XYZ”

Quantification: Repeated Characters or Sequences
There are several codes defining that a character or sequence of characters which is found before this code has to be repeated several times.

The “*” allows any number of repeated characters (or sequences).
Example: “ABC*” will accept any string with “AB” and any number of Cs (0 to unlimited).

The “+” is similar to “*”, but requires at least one character (or sequence).
Example: “ABC+” will accept any string with “ABC” and any number of Cs after that.

The “?” code means zero or one occurrence of the last character (or sequence).
Example “ABC?” will accept “AB” or “ABC”.

{1,5} stands for 1 to 5 occurrences of the character or sequence before this code,
{5,} stands for “at least 5” occurrences,
{,5} stands for “up to 5” occurrences and
{5} stands for “exactly 5” occurrences.
Example: “ABC{3,5}” accepts any string that starts with “AB” followed by at least 3 and no more than 5 Cs.

You can use these codes also with sequences like “(ABC)” or “[A-Z]”
Example: “[A-Z]{5,}” will accept any string that is at least 5 characters long and consists of the letters A-Z.

If you want to disallow any characters before or after your codes, please remember to add ^ and $.
Example: “^ABC[0-9]{1,5}$” stands for any string that starts with ABC followed by 1 to 5 numbers.

Please use a Regular Expression Tester to check your entries:
https://regex101.com/
https://regexr.com/
https://www.freeformatter.com/regex-tester.html

More information can be found at:
https://en.wikipedia.org/wiki/Regular_expression
http://www.regular-expressions.info/
http://www.phpbuilder.com/columns/dario19990616.php3