Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Values Tab - Regular Expression Question
#1
Is there any documentation on how to form a regular expression in the Values Tab for a CheckBox widget.

I'm trying to set a false value if the field is equal to either of two values. I assume I need to use the Regular Expr form to do that. Example, I have a CQC Variables driver field called Rain8Mode. It can be Off, Summer, Winter, Rain or Manual. In the Check Box widget, I'm trying to set the false Value if the field is Off or Rain. It would be true if the field was either Summer, Winter or Manual. Is there away to do this. Thanks.
Reply
#2
CQC supports the basic regular expression stuff. For something like that, it would be something like:

(Off|Rain)

Meaning, Off OR Rain. No spaces around the | or inside/outside the parens since spaces count as part of the pattern. Try that and see what it does for you.
Dean Roddey
Explorans limites defectum
Reply
#3
Dean, I did get that to work. So thanks. But, is there anymore documentation on what a "regular expression" can look like? I guess I'm not too familiar with the term "regular expression". Thanks again.
Reply
#4
In a nutshell, it comes down to a sequence of characters that are used to match a pattern. It's composed of one of a set of components:

1. Characters. Just regular characters to be matched

ABC means match A, then B, then C

2. Any single character is represented by a period, so:

A.C will match A1C, A2, A4C, AxC and so forth

3. One of a set of things, divided by a | character, so:

A|B will match a single A or single B.
(A|B)(C|D) will match AC, AD, BC, or BC

4. Repetition indicators. ?=One or zero, *=Zero or more, +=One ormore

AB?C will match ABC or AC, since one or zero Bs can be between them
AB+C will match ABC, ABBC, ABBBBBBC, and so on, because one or more Bs are legal
AB*C will match AC, ABC, ABBBBC, and so on, because zero or more Bs are legal.

5. Range indicators, using []

[A-Z] will match any letter from capital A to capital Z
[0-9] will match any digit
[123] will match a one, two or three (so it's kind of like (1|2|3) really, but just demonstrating that it's not necessarily a range like the first two.)


You can mix these things together in many ways, particularly by using the parenthesis, because the repetitions apply to the whole parethesized previous section if it is parenthesized, or to the range.

(A|B)+CD will match ACD, BCD, ABCD, AAAABBBBCD and so forth, because it's one or more As or Bs followed by CD.

One|Two will match either One or Two.

(Two|Four) (Rabbits|Foxes) will match "Two Rabbits", "Four Rabbits", "Two Foxes" or "Four Foxes".

[0-9]* will match any number of digits (ncluding zero digits)

[0-9]+Db will match 0Db, 0132Db and so forth, i.e. one or more digits followed by Db.

(1|2)[5-9][A-F] would match 15A, 29C, and so forth. It's 1 or 2, followed by one digit from 5 to 9, followed by one character from A to F.

[^ACD]+ means one or more characters, none of which can be A, C, or D.

A.*B would mean A followed by zero or more of any character, followed by a B.


Of course you have to escape the magic characters to get them to be treated as regular characters. So:

\[\(\* would match [(* because they are all escaped. \\ represents a single \ character, since you have to escape the escape character as well.


That's it in a nutshell. There are a few more aspects to it, but that's the most important stuff. You can write quit elaborate ones, but they can be hard to prove correct just by looking at them.

And you cannot use regular expressions to count things. So there's no regular expression that says "four A, B, or C characters.". You would hav eto just do:

(A|B)(A|B)(A|B)(A|B)

And explicitly indicate all four options.
Dean Roddey
Explorans limites defectum
Reply
#5
Right. I knew that.
Reply
#6
Dean,

You explaination of regular expressions is very good. Can you please add it to the documentation section so that it does not get lost. I have been wondering about this for some time and can never seem to find the answer on your site.
David
Z-Wave World Magazine|Baltimore Hackerspace
"Why think outside the box when you could let the box think for you." - My take on Home Automation
Reply
#7
Yeh, I'll get it documented. The problem so far is that there's no one place to put it. It's not really part of any specific piece of the system, and it's not CQC specific. Maybe I'll do a FAQ entry for it.
Dean Roddey
Explorans limites defectum
Reply
#8
Dean Roddey Wrote:And you cannot use regular expressions to count things. So there's no regular expression that says "four A, B, or C characters.". You would hav eto just do:

(A|B)(A|B)(A|B)(A|B)

And explicitly indicate all four options.
Is that your implementation of regexps that has this limitation, or the lib you're using?

With most implementations, you can do:

(A|B){4}

to do what you did above.

The {} modifier is actually {n,m} where n is the lower limit and m the higher limit. If one is omitted, it matches all values upto (or from) that value. eg, "?" is the same as "{,1}".

Chris.
Reply
#9
You also didn't mention the anchors (^ and $).

^ ties the search to the start of the string, $ to the end.

Looking for "^foo" will only match strings that begin "foo" and "bar$" strings that end in bar. "^foobarbaz$" matches only strings that are exactly "foobarbaz".

Chris.
Reply
#10
Quote:Is that your implementation of regexps that has this limitation, or the lib you're using?

That's my implementation, which doesn't implement counting.

Quote:You also didn't mention the anchors (^ and $). ^ ties the search to the start of the string, $ to the end.

Yeh, those are some of the 'other bits' that I mentioned but left out. I mainly left them out because they aren't relevant in the situation he was asking about. In those cases, the entire input value has to match or it fails, so the anchors would just be redundant. But, in other cases, they could be of use.
Dean Roddey
Explorans limites defectum
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  SSL Certificate Question gReatAutomation 1 510 10-26-2020, 07:48 AM
Last Post: gReatAutomation
  V2 Question - OpenWeatherMap Using their New JSON Data Feed kblagron 7 1,317 05-07-2020, 01:40 PM
Last Post: Dean Roddey
  Dynamic Overlay Question bryanb 4 761 04-17-2020, 03:48 AM
Last Post: bryanb
  Triggered Event on Timer Question znelbok 7 2,263 12-09-2019, 02:10 PM
Last Post: znelbok
  Question on CQC Driver Pack Install kblagron 1 820 11-26-2019, 06:38 PM
Last Post: Dean Roddey
  Regular Expression in Comp Val gReatAutomation 30 6,750 09-18-2019, 04:35 AM
Last Post: gReatAutomation
  SONOS Driver Question gReatAutomation 13 3,567 08-23-2019, 12:37 PM
Last Post: Dean Roddey
  Runtime Values gReatAutomation 4 854 08-12-2019, 06:07 PM
Last Post: gReatAutomation
  Insteon V2 Driver Question kblagron 1 813 08-01-2019, 10:51 AM
Last Post: kblagron
  Question on Parsing a String in a CML Macro kblagron 2 1,033 06-18-2019, 06:21 PM
Last Post: Dean Roddey

Forum Jump:


Users browsing this thread: 1 Guest(s)