Using negative lookaheads for non-matching content checks in regular expression for synthetic monitors

Using negative lookaheads for non-matching content checks in regular expression for synthetic monitors

What is a negative lookahead?

A negative lookahead assertion in regular expression (RegEx) checks if the pattern inside the lookahead does not match with the input string.

The syntax for the negative lookahead is (?! pattern).
(?!) - negative lookahead
(pattern) - the pattern must not match with the input string

Use case

Consider a website that uses a synthetic monitor. You don't want the word Error in the website content. If the content has the word Error, then the monitor will trigger an alert. This can be achieved using the negative lookahead in RegEx.

Example

Exclude Error from the webpage.

Input for Should match regular expression: ^(?s)(?!.*Error).*$

Explanation for the above RegEx:
^ — Start of the string
(?s) — Enables DOTALL mode, making newline characters match
(?!.*Error) — Negative lookahead ensuring Error is not in the string
.* — Matches any sequence of characters (including newlines)
$ — End of the string

When the above RegEx is entered in the content checks, it checks for the word Error in the webpage. When the word Error is encountered, the monitor triggers an alert message.

Example 1: You've successfully logged in.
Note: The word Error is not available in the above response. So, the RegEx should match, and the monitor will stay up.

Example 2: Error with a user name and password.
Note: The word Error is in the above response. So, the RegEx should not match, and the monitor will trigger an alert.
 
    • Related Articles

    • Compare our various methodologies for Website Monitoring

      Get to know Site24x7 monitors better and choose the one that best fits your monitoring needs. Compare the functionality of the following monitors: Website Monitoring Webpage Speed (Browser) Web Transaction Monitoring Web Transaction (Browser) SSL/TLS ...
    • Troubleshooting false positive alerts in monitoring

      Problem False positive alerts are being generated. Possible cause The monitoring system is down in some locations. The Website monitor might be configured for one location, such as Seattle, but may appear down when accessed from another location, ...
    • Monitor and validate DNS IP changes using regex

      DNS administrators often monitor their DNS servers to detect changes in domain resolution and ensure IP mappings remain secure and accurate. Problem When your organization adds or modifies an IP address for your domain name, it’s critical to: Be ...
    • Difference between website monitoring and REST API monitoring

      Website monitoring allows you to monitor your websites and web applications to ensure that they are up and running. Website monitor verifies the availability of specified, addressable, standard HTTP and HTTPS URLs from over 100+ global locations and ...
    • Why is my website response time too high from China?

      If your website is hosted outside China and you have chosen China as the location for monitoring, then the website response time will be high. This is because of the Great Firewall policy followed by China wherein, all the data coming from outside ...