Announcement

Collapse
No announcement yet.

regular expression syntax question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • regular expression syntax question

    Hello,

    I need to find a solution to "match" on a string which does NOT contain certain words. I've used a few regular expression "testers" to validate my expression, however, it doesn't seem to work the way I would have expected using EasyTrigger in an event. Maybe the double negative is confusing me though.

    Would someone mind giving this a look and let me know if you think there's an issue:

    ^((?i)(?!rain|freezing|ice|icy|showers).)*$

    So, if the input string was: "Sunny with a few clouds" or "overcast and crappy", these would result in a "match" (or what I would consider to be "true" in an IF/Then event).

    However, if the string was: "Cloudy with light showers" or "Freezing rain", the result should NOT be a match, or be considered false for the IF/Then event.

    Is there something I'm missing or something else required for EasyTrigger's implementation of Regular Expressions?

    One of the online "testers" I used was: https://regex101.com/

    Thanks!

  • #2
    Originally posted by dhalsall View Post
    Hello,

    I need to find a solution to "match" on a string which does NOT contain certain words. I've used a few regular expression "testers" to validate my expression, however, it doesn't seem to work the way I would have expected using EasyTrigger in an event. Maybe the double negative is confusing me though.

    Would someone mind giving this a look and let me know if you think there's an issue:

    ^((?i)(?!rain|freezing|ice|icy|showers).)*$

    So, if the input string was: "Sunny with a few clouds" or "overcast and crappy", these would result in a "match" (or what I would consider to be "true" in an IF/Then event).

    However, if the string was: "Cloudy with light showers" or "Freezing rain", the result should NOT be a match, or be considered false for the IF/Then event.

    Is there something I'm missing or something else required for EasyTrigger's implementation of Regular Expressions?

    One of the online "testers" I used was: https://regex101.com/

    Thanks!
    I can't get regexmatch to work right either on a string match... It seems everything is a match or "true". For now here is a workaround if all you want to exclude is the 5 words you listed above.

    Click image for larger version

Name:	doesnotcontain.png
Views:	28
Size:	50.6 KB
ID:	1297914

    I tested this on a control device and it works. Note however that the match type is lazy, so "draining", "rice" and "shower" will all match.

    --Barry

    Comment


    • #3
      you are right, the trigger "This device's string changes and matches this regular expression..." didn't work at all (the condition "This device's string matches this regular expression..." worked as expected though)
      I fixed it in version 3.0.0.64 which is available in the Beta section of the updater. I tested it on your example and it works as expected now.

      Thank you for reporting this bug.

      Comment


      • #4
        Thank you both!

        Spud: I will update to the beta and give it another try, sounds like that will be the fix!

        - Dave

        Comment


        • #5
          'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.'

          Comment


          • #6
            Originally posted by baudi View Post
            'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.'
            haha
            -Wade

            Comment


            • #7
              Originally posted by baudi View Post
              'Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.'
              Haha.. That quote is a gem. I like this one too: “Give a man a regular expression and he’ll match a string… teach him how to create them and you’ve given him enough rope to hang himself”

              RegEx to a hobbyist like me is like dynamite and blasting caps to a farmer... Amazing tool, until you lose a few fingers.

              --Barry

              Comment


              • #8
                Hi Spud, my apologies for not getting back sooner. I did upgrade to .64 last week and haven't had time to properly test it... but my routine still seems to be true in all cases (as it's freezing rain today). I will give this more time to troubleshoot next week, but is there anything I should have done when I installed the beta (deleting the old version perhaps?).

                much appreciated,
                Dave

                Comment


                • #9
                  Originally posted by dhalsall View Post
                  Hi Spud, my apologies for not getting back sooner. I did upgrade to .64 last week and haven't had time to properly test it... but my routine still seems to be true in all cases (as it's freezing rain today). I will give this more time to troubleshoot next week, but is there anything I should have done when I installed the beta (deleting the old version perhaps?).

                  much appreciated,
                  Dave
                  I just tested and it works for me. Note however your expression is "greedy" for the duration of the string, so the string "The free pizza I eat on the train after the show was nice and spicy" would yield 5 negative matches in the example from your original post.

                  Try this and see if it improves your results:

                  Code:
                  ^((?i)(?!\brain\b|\bfreezing\b|\bice\b|\bicy\b|\bshowers\b).)*$

                  --Barry

                  Comment


                  • #10
                    Hi Barry,

                    Thank you for the suggestion - that is a much better method! My apologies for not getting to this sooner, but it took time for me to redirect my XML to a location I could edit to create fake weather. I was quite sure your method was going to fix this finally... but nope.

                    However, after a lot of fumbling around, the issue the entire time was - A CORRUPTED EVENT! I guess when I changed the trigger to this method, behind the scenes it wasn't doing what visually it was saying it was doing (there were a few groups of OR IF/AND IF's). I simply copied the event, disabled the original one... AND THEN IT WORKED!

                    I wish HS would let you turn on a debug log mode so you could see what the trigger logic was, it might have helped me realize the Event was buggered.

                    Once again, thanks a bunch, and I've also implemented the Word Boundaries... and learned a tad more about RegEx

                    Dave

                    Comment


                    • #11
                      Originally posted by dhalsall View Post
                      Hi Barry,

                      Thank you for the suggestion - that is a much better method! My apologies for not getting to this sooner, but it took time for me to redirect my XML to a location I could edit to create fake weather. I was quite sure your method was going to fix this finally... but nope.

                      However, after a lot of fumbling around, the issue the entire time was - A CORRUPTED EVENT! I guess when I changed the trigger to this method, behind the scenes it wasn't doing what visually it was saying it was doing (there were a few groups of OR IF/AND IF's). I simply copied the event, disabled the original one... AND THEN IT WORKED!

                      I wish HS would let you turn on a debug log mode so you could see what the trigger logic was, it might have helped me realize the Event was buggered.

                      Once again, thanks a bunch, and I've also implemented the Word Boundaries... and learned a tad more about RegEx

                      Dave

                      Awesome! Glad that worked for you. It seems I recall reading somewhere there is a known "bug" with Homeseer where if you delete an IF trigger which then causes an AND IF condition to move up and become the trigger, the event will never fire. Maybe that's what happened in your case? Nevertheless, glad it's working for you now.

                      .

                      --Barry

                      Comment

                      Working...
                      X