Regex – Regular Expression
Cradle provides support for regular expressions, regular expressions are a means to find variable text in places such as:
- Queries
- Find dialogs
- Category recognition strings
- Category value validations
For instance, regular expressions (regexes) can be used in queries to find all items in which any frame, or a specific frame, or any of a list of frames, contains text matching the regular expression that you are searching for. For example, if you wanted to find all items containing sequences of capital letters followed by numbers, then the regular expression would be:
[A-Z]+[0-9]+
Whilst you are here, take a look at Why is Requirements Management Essential for your Business?
Special Characters
Some characters have special meanings within regexes these characters are:
Char | Description | Meaning |
\ | Backslash | Used to escape a special character |
^ | Caret | Beginning of a string |
$ | Dollar sign | End of a string |
. | Period or dot | Matches any single character |
| | Vertical bar or pipe symbol | Matches previous OR next character/group |
? | Question mark | Match zero or one of the previous |
* | Asterisk or star | Match zero, one or more of the previous |
+ | Plus sign | Match one or more of the previous |
( ) | Opening and closing parenthesis | Group characters |
[ ] | Opening and closing square bracket | Matches a range of characters |
{ } | Opening and closing curly brace | Matches a specified number of occurrences of the previous |
Examples
Finished\? matches “Finished?”
^http matches strings that begin with http
[^0-9] matches any character not 0-9
ing$ matches “exciting” but not “ingenious”
gr.y matches “gray“, “grey”
Red|Yellow matches “Red” or “Yellow”
colou?r matches colour and color
Ah? matches “Al” or “Ah”
Ah* matches “Ahhhhh” or “A”
Ah+ matches “Ah” or “Ahhh” but not “A”
[cbf]ar matches “car“, “bar“, or “far”
[a-zA-Z] matches ascii letters a-z (uppercase and lower case)
Using Special Characters as Literal Characters
If you want to use any of these as literal characters you can escape special characters with \ to give them their literal character meaning.
Example
If you want to match 1+2=3, you need to use a backslash (\) to escape the + as this character has a special meaning (Match one or more of the previous).
To match the 1+2=3 as one string you would need to use the regex 1\+2=3
For further information on using regexes in Cradle see our online help.