How to Use Regular Expressions in Testomato
Testomato supports the use of advanced web page monitoring filtering: regular expressions (regex). This means that you can use regular expression patterns for defining a rule or rules set up to monitor your websites.
What Are Regular Expressions
A regular expression is a sequence of characters that define a search pattern, which is mainly used for string pattern matching and string finding. Basically, they are coded strings that define an infinite number of possible matches.
While regular expressions are not considered a programming language, they do use complex combinations of characters and symbols that can make them difficult to interpret. These special characters which have a special meaning in regex (known as metacharacters) make regular expressions one of the most powerful and flexible tools for parsing and filtering specific text on a page.
Here’s a quick list of some basic regular expressions:
For more, check out this cheat sheet from RexEgg.
Using Regular Expressions in Testomato
With Rules, you can configure checks to see if a particular word or phrase is present on a page in your website content. You can also create Rules based on whether a particular regular expression matches with website content.
Take a look at the following examples:
1) Check a URL redirects to a location with no other URL parameter followed
^https://testomato.com/\?backlink=[^&]+$
Explanation:
- ^ assert position at start of the string
https://testomato\.com/\?backlink=
matches the characters literally[^&]+
match everything except&
betweenone
andunlimited
times$
assert position at the end of the string
2) Check that / is not disallowed in robots.txt, but Disallow: /admin is ok
^Disallow: /$
Explanation:
^
assert position at the start of the lineDisallow:/
matches the charactersDisallow: /
literally$
assert position at the end of a line
3) Check page contains “word test” (but does not match “world contest”)
\btest\b
Explanation:
\b
assert position at a word boundary(^\w|$|\W\w|\w\W)
test
matches the characterstest
literally\b
assert position at a word boundary(^\w|$|\W\w|\w\W)
If you need a quick cheat sheet, you can use regex101.com to highlight patterns and matches.
Have more questions about using regular expressions in Testomato?
Let us know in the comments below or email our team support@testomato.com. You can also tweet us directly @testomatocom.