- Using regular expressions lets you verify or select text even if you do not know exactly what the text is.
- Using a system of placeholders for characters and some function symbols, you can enter a regular expression to find or check a text.
- Actions which support regular expressions have an additional parameter, "Operator". From this combo box, you can choose "matches" to indicate that you want to use regular expressions.
Simple matching
- "abc" matches "abc" and nothing else.
Wildcards
- "." represents one instance of any character.
- ".." represents two characters.
Repetition
- Instead of using "." for each character, you can use symbols to indicate how many characters you are replacing with wildcards.
- "?" matches the previous character or group 0 or 1 time(s). E.g. "a?" represents ''none or one "a"''.
- "*" matches the previous character or group 0 or more time(s). E.g. "a*" represents ''none or more "a"''.
- "+" matches the previous character or group 1 or more time(s). E.g. "a+" represents ''one or more "a"''.
- You can also use curly brackets "{}" to specify the minimum and maximum number of repetitions, e.g. "{4,7}" looks for a minimum of four and a maximum of seven repetitions of the previous character.
- To specify that a character must be repeated a minimum of four times, use: "{4,}"
Combining wildcards with repetition
- You can specify a whole area of unknown text using "." and one of the repetition methods.
- ".*" is an unlimited amount of any character, or none at all.
- ".?" is 0 or one of any character.
- ".+" is an unlimited amount of any character, but the character must appear at least once.
![\includegraphics[height=2cm]{lightbulb}](img1.jpg) |
Jubula applies your regular expression to your entire string. To search for a match within a string, wildcards need to be placed on either side. See the examples below for more information. |
Ranges
- For each individual character, you can specify a range of things it is allowed to be.
- A range is specified using square brackets ("[]") and a dash "-".
- For example, you can specify that a particular character can be any capital letter: "[A-Z]".
![\includegraphics[height=2cm]{lightbulb}](img1.jpg) |
Note that there are no spaces between the ranges. |
Alternatives
- Use a pipe ('|') to specify alternatives.
- For example, "[a|b].*" will match a string that begins with "a" or "b".
Escape character
- Backslash "
" is used to negate the effect of the character following the backslash. - The characters that are used to construct a regular expression need to be escaped if they are to be matched within a string.
- The characters are:
[ ] \ . | ? * + ( ) { } ^ $
- Because Jubula already uses a backslash as an escape symbol, you will need to use two backslashes to escape regular expression characters.
- For example, to check for a tree node:
"x/y/z/***"
where the slashes are a part of the node, your regular expression in Jubula would look like this: x\/y\/z\/\\*\\*\\*
The backslashes before the ordinary slashes are an escape symbol to tell Jubula that the following sign is not a path separator. The extra backslash before the stars tells Jubula that the second backslash is to be interpreted as a backslash in the regular expression, i.e. as an escape symbol. - E.g. If you want to check for a star ("*"), then you have to enter "

*".
Verbatim
- You can avoid having to use multiple backslashes by putting the whole regular expression in single quotes:
- The example above for a tree node could be entered thus:
"'x/y/z/***'"
Useful examples
- An empty field is represented by:
^$
- A string that starts with "a" is represented by: "a.*"
- A string that ends in "a" is represented by: ".*a"
- A string that starts with "a", ends in "b" and has unknown values (0 or more) in the middle is represented by: "a.*b"
- A string which contains "a" somewhere between other unknown characters (0 or more) is represented by: ".*a.*"
- A password which can only contain capital letters and which must be between six and eight letters is represented by: "[A-Z]{6,8}".
- A password which can contain any alphanumerical values and which must be at least six characters is represented by: "[A-Za-z0-9]{6,}".
- You can check that a string corresponds to a minimum and maximum length using:
'^.{'={MIN_COUNT}','={MAX_COUNT}'}$'
- To check for a text which begins with a "*", you must use the escape character:
\\*.*
- To check that a specific string is not in a text, use:
^.*[^(STRING)].*\$
For additional information about syntax and usage of regular expressions in general, please consult one of the many textbooks on the subject.
Copyright BREDEX GmbH 2011. Made available under the Eclipse Public License v1.0.