1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Creating a Perl Compatible Regular Expression for use in PRTG Network Monitor

Discussion in 'HTML, Graphics & Programming' started by Feek, Oct 29, 2018.

  1. Feek

    Commissario

    Joined: Oct 17, 2002

    Posts: 24,773

    Location: In the radio shack

    I wonder if someone can help me please. This may or may not be possible.

    I use PRTG to monitor some web page and I want it to error if it detects the following lines in a page of html.

    Code:
    <td bgcolor="GREEN"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM1
    <td bgcolor="RED"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM2
    <td bgcolor="GREEN"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM3

    Unfortunately these lines don't just follow each other, they're not consecutive within the html otherwise it'd be easy to check for their presence.

    PRTG supports Perl Compatible Regular Expressions (PRCE) as described here and I'm struggling to create one which checks for the presence of the three lines above.

    Is it possible to use a Perl Compatible Regular Expression for this? If so, what on earth should it be?

    Thanks.
     
  2. RoyMi6

    Mobster

    Joined: Mar 9, 2010

    Posts: 2,523

    Test your regular expressions here:

    https://regex101.com/

    Paste in a sample of your output you want to test then play with writing regular expressions to match. Default even uses PRCE.

    In principle though you could just do something as simple as using the pipe( | ) operator which does an "OR" to search for your three strings.

    So...

    <td bgcolor="GREEN"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM1
    OR
    <td bgcolor="RED"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM2
    OR
    <td bgcolor="GREEN"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM3

    Would be...

    <td bgcolor="GREEN"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM1|<td bgcolor="RED"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM2|<td bgcolor="GREEN"><FONT FACE="VERDANA" SIZE="2" COLOR="WHITE"><B>ITEM3

    Your strings don't contain any special characters in the eyes of of a Regex expression so you shouldn't need to do anything special if you're using a GUI to change this.

    You might want to make it case insensitive (/i) and maybe not include the "ITEM1" / "ITEM2" / "ITEM3" part if that can possibly change.

    EDIT: Oh if there might be line breaks in the output then best to allow any whitespace characters between words:

    https://regex101.com/r/gXyOee/1/
     
    Last edited: Oct 30, 2018
  3. Feek

    Commissario

    Joined: Oct 17, 2002

    Posts: 24,773

    Location: In the radio shack

    Turns out it accepts wildcards so I was able to use a single string. Sorted.