This page provides examples of using correct escaping when using regular expressions in various contexts.
When using the trigger expression constructor, correct escaping in regular expressions is added automatically.
User macro with context
Regular expression: \.+\"[a-z]+
User macro with context: {$MACRO:regex:"\.+\\"[a-z]+"}
Notice:
Macro function inside item key parameter
Regular expression: .+:(\d+)$
Item key: net.tcp.service[tcp,,"{{$ENDPOINT}.regsub(\".+:(\d+)$\",\1)}"]
Notice: - regular expression inside the regsub
macro function is double-quoted (because of contains closing parenthesis); - quotation marks around the regular expression are escaped (because the whole third item parameter is double-quoted); - third item key parameter is double-quoted because it contains a comma.
LLD macro function
Regular expression: \.+\"([a-z]+)
LLD macro: {{#MACRO}.iregsub("\.+\\"([a-z]+)", \1)}
Notice:
LLD macro function inside user macro context
Regular expression: \.+\"([a-z]+)
LLD macro: {{#MACRO}.iregsub("\.+\\"([a-z]+)", \1)}
User macro with context: {$MACRO:"{{#MACRO}.iregsub(\"\.+\\\"[a-z]+\", \1)}"}
Notice:
String parameter of function (any)
concat
is used as example.
String content: \.+\"[a-z]+
Expression: concat("abc", "\\.\\\"[a-z]+")
Notice:
LLD macro function inside string parameter of function
Regular expression: \.+\"([a-z]+)
LLD macro: {{#MACRO}.iregsub("\.+\\"([a-z]+)", \1)}
Expression: concat("abc, "{{#MACRO}.iregsub(\"\\.+\\\\\"([a-z]+)\", \\1)}")
Notice:
User macro with context inside string parameter of function
Regular expression: \.+\"[a-z]+
User macro with context: {$MACRO:regex:"\.+\\"[a-z]+"}
Expression: concat("abc, "{$MACRO:regex:\"\\.+\\\\\"[a-z]+\"}")
Notice:
LLD macro function inside user macro context inside function
Regular expression: \.+\"([a-z])+
LLD macro: {{#MACRO}.iregsub("\.+\\"([a-z]+)", \1)}
User macro with context: {$MACRO:"{{#MACRO}.iregsub(\"\.+\\\"([a-z]+)\", \1)}"}
Expression: concat("abc, "{$MACRO:\"{{#MACRO}.iregsub(\\\"\.+\\\\\\\"([a-z]+)\\\", \\1)}\"}")
Notice the three layers of escaping:
User macro with context just inside string
Regular expression: \.+\"[a-z]+
User macro with context: {$MACRO:regex:"\.+\\"[a-z]+"}
Inside string of some expression, for example: func(arg1, arg2, arg3)="{$MACRO:regex:\"\\.+\\\\\"[a-z]+\"}"
Notice: