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

    • How does the Poll Strategy setting work for website monitors?

      When configuring thresholds for performance metrics, you can set strategies that the website monitor will use to send alerts during a threshold breach. There are twelve options available: Poll count Poll average Time duration Average time Poll sum ...
    • 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 ...
    • 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 ...
    • 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, ...
    • Monitors that require On-Premise Pollers in Site24x7

      Certain monitor types in Site24x7 require the use of On-Premise Pollers for data collection, especially when monitoring internal, firewall-restricted, or private resources. Depending on the type of monitoring, additional modules like the Network ...