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

    • Adding content checks to a monitor.

      Content checks can be added as part of your monitor configuration. The following monitors support content checks: Website  Web Transaction Web Transaction (Browser) Port (Custom Protocol) REST API (Text, XML and JSON) REST API Transaction (Text, XML ...
    • Configure the On-Premise Poller as a monitoring location for synthetic (browser) monitors

      If you need to monitor from an internal network, install an On-Premise Poller and use it as a monitoring location for your synthetic (browser) monitors. Synthetic (browser) monitors include Web Transaction (Browser), Web Transaction (Browser) - ...
    • 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 Web Page Speed (Browser) Web Transaction Monitoring Web Transaction (Browser) ...
    • 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 four options available: Poll count Poll average Time duration Average time The default ...
    • Support for RegEx in Linux process monitoring

      Use Case: Consider a Java process being monitored by our server monitoring agent. Every time the process is restarted, the process arguments might change. During this scenario, the process will be marked as Down and it wont be changed to the Up ...