Highlight from variable on multiple values

Posted by Rhien on Thu 21 Dec 2017 06:02 PM — 4 posts, 15,400 views.

#0
Having an issue getting highlighting to work with a variable that has multiple values, although if I put the value of that variable directly into the regex it works.

Variable Contents:


  <variable name="target">John|Bob|Jim|Freddy</variable>


This trigger does not work:


  <trigger
   custom_colour="2"
   enabled="y"
   expand_variables="y"
   group="Highlighted Words"
   ignore_case="y"
   keep_evaluating="y"
   match="\b(@target)\b"
   regexp="y"
   repeat="y"
   send_to="12"
   sequence="99"
   other_text_colour="red"
  >


This trigger does work:


  <trigger
   custom_colour="2"
   enabled="y"
   expand_variables="y"
   group="Highlighted Words"
   ignore_case="y"
   keep_evaluating="y"
   match="\b(John|Bob|Jim|Freddy)\b"
   regexp="y"
   repeat="y"
   send_to="12"
   sequence="99"
   other_text_colour="red"
  >


Now, to prove the variable is making it into the match I changed @target to have a single name and then it works (but it stops working when I put an additional value separated by a pipe in the variable).
#1
I think I answered my original question again, although I don't understand why so maybe I'll change that to my question.

I changed "@target" to "@!target" and then it worked with the piped string list. I saw another example where someone used that syntax and thought I'd try (and it worked).

I guess my new question is, What is the difference between "@target" and "@!target"?
Australia Forum Administrator #2
If you use @target the client assumes you might have any text there, and in order to make the regexp "safe" will put backslashes before magic characters, to that "|" will become "\|".

If you use the @!target method this suppresses this action, so that you can use special regexp characters (as you have done) in the variable.
#3
Got it. Thanks again Nick.