Regular expressions |
Proteus supports two types of regular expressions: simple and extended.
Extended regular expressions are more powerful, but also more complex to use; they consist in a string of characters where a few are interpreted literally, while others are control characters with a special meaning. This is a brief explanation about them:
The evaluation order for operators at the same level of parenthesis is (from highest to lowest priority):
[] *+? concatenation |
A few examples of extended regular expressions (used by REXMATCH, REXIMATCH and others):
"^a" | accept any string beginning with 'a' |
"^apples" | accept any string beginning with 'apples' |
"a$" | accept any string ending with 'a' |
"oranges$" | accept any string ending with 'oranges' |
"f..e" | accept any string of 4 letters beginning with 'f' and ending with 'e' (e.g. 'free', 'fare' but not 'force') |
"[ab]" | accept any string containing 'a' or 'b' |
"[^ab]" | accept any string not containing 'a' and 'b' |
"^[0-3][0-9]/[0-1][0-9]/[0-9][0-9]$" | accept any date (like "30/12/97") |
"su(m|n)" | accept any string containing the word 'sum' or 'sun' (not 'su') |
"worl?d" | accept any string containing "word" or "world" |
"^[0-9]*$" | accept an empty string or a number containing only the digits '0'-'9' |
"^[a-zA-Z]+[a-zA-Z0-9]*$" | accept an identifier name (start with a letter, can contain only alphanumeric characters, is at least one character long) |
"^(hello)|(goodbye)$" | accept only the two strings 'hello' and 'goodbye' |
Additional details can be found here.
Simple regular expressions are easier to use than extended regular expressions; they only include two special characters:
The comparis is case-unsensitive when using the function IMATCH:
"b*o" matches "bo", "boo", "BO", "BriO" and so on.
A few examples of simple regular expressions (used by MATCH, IMATCH and others):
"*su?*" | accept any string where the two characters 'su' are followed by a single character (e.g. 'sum', 'sun', etc.) |
"c*" | accept any string starting with 'c' |
"*a" | accept any string ending with 'a' |
"???" | accept any string 3-character long |
"*one*two*three*" | accept any string including the words 'one', 'two' and 'three' in this order |
Additional details can be found here.
Start of page | Next topic | Previous topic | Contents | Index |