Ad Widget

Collapse

[Zabbix 5.0] Telegram Webhook RegEx Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • heine.y
    Junior Member
    • Oct 2020
    • 5

    #1

    [Zabbix 5.0] Telegram Webhook RegEx Problem

    Hey there,

    I'm having an issue with the JavaScript for my Telegram Webhook. I'm using HTML markdown, so I have to substitute '<', '>' and '&' from the trigger name and operational data.

    I still wanted to be able to use html markdown in the message template, so I used the following regex to match all '<', '>' and '&' characters that are not part of a html tag:
    Code:
    var safesubject = params.Subject.replace(/&/g,'&amp;');
    safesubject = safesubject.replace(/<(?!\/?\w>)/g,"&lt;");
    safesubject = safesubject.replace(/(?<!<\/?\w)>/g,"&gt;");
    
    var safemessage = params.Message.replace(/&/g,'&amp;');
    safemessage = safemessage.replace(/<(?!\/?\w>)/g,"&lt;");
    safemessage = safemessage.replace(/(?<!<\/?\w)>/g,"&gt;");
    However, this fails at the third line, complaining about the regex. (This works in in chrome, btw, tested it in it's console)

    The Duktape Engine version appears to be too old to support negative lookbehind. Which is quite unfortunate imo.

    Can anybody help me with getting this to work?
    Thank you in advance.
    Last edited by heine.y; 27-10-2020, 12:38.
Working...