Posts: 426
Threads: 39
Joined: May 2006
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.
Posts: 40,428
Threads: 489
Joined: Aug 2002
CQC supports the basic regular expression stuff. For something like that, it would be something like:
(OffRain)
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
Posts: 426
Threads: 39
Joined: May 2006
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.
Posts: 40,428
Threads: 489
Joined: Aug 2002
02062007, 07:31 PM
(This post was last modified: 02062007, 07:33 PM by Dean Roddey.)
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:
AB will match a single A or single B.
(AB)(CD) 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 []
[AZ] will match any letter from capital A to capital Z
[09] will match any digit
[123] will match a one, two or three (so it's kind of like (123) 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.
(AB)+CD will match ACD, BCD, ABCD, AAAABBBBCD and so forth, because it's one or more As or Bs followed by CD.
OneTwo will match either One or Two.
(TwoFour) (RabbitsFoxes) will match "Two Rabbits", "Four Rabbits", "Two Foxes" or "Four Foxes".
[09]* will match any number of digits (ncluding zero digits)
[09]+Db will match 0Db, 0132Db and so forth, i.e. one or more digits followed by Db.
(12)[59][AF] 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:
(AB)(AB)(AB)(AB)
And explicitly indicate all four options.
Dean Roddey
Explorans limites defectum
Posts: 426
Threads: 39
Joined: May 2006
Posts: 1,254
Threads: 103
Joined: Aug 2005
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.
Posts: 40,428
Threads: 489
Joined: Aug 2002
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
Posts: 484
Threads: 28
Joined: Apr 2006
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:
(AB)(AB)(AB)(AB)
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:
(AB){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.
Posts: 484
Threads: 28
Joined: Apr 2006
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.
Posts: 40,428
Threads: 489
Joined: Aug 2002
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
