Page 1 of 1

Use regex in condition with variables

Posted: Mon Jan 18, 2021 2:30 pm
by PdFUser5000
I think this is a noob question, but i hope someone can confirm this is correct/wrong.

I have a connector, which has Conditions in variables defined to the "Include these jobs" option.

Currently, i have created a new condition for each new "ID" of a model. This creates a very long list of conditions.


Can i wrap it up in a single condition( Capture 2), which uses regexp? I tried, but it does not seem to be working. Am i doing something wrong? Can i even do this?
Capture2.PNG
Capture2.PNG (3.88 KiB) Viewed 5309 times

Re: Use regex in condition with variables

Posted: Mon Jan 18, 2021 3:04 pm
by mkayyyy
To use a regular expression as the right-hand side condition you need to use the Matches or Does not match Comparison operators

Re: Use regex in condition with variables

Posted: Mon Jan 18, 2021 3:16 pm
by PdFUser5000
Because there are other symbols in the filename, i came up with this. It seems to be working. But is this correct?

[Job.NameProper:Search="(A135.2|A115|C5016|A5012|A5013|B32.2|B33.1|C5010|C5011|C5014|C5015|C5018)"]

Matches

(A135.2|A115|C5016|A5012|A5013|B32.2|B33.1|C5010|C5011|C5014|C5015|C5018)

Re: Use regex in condition with variables

Posted: Mon Jan 18, 2021 4:21 pm
by freddyp
It is correct, but there is something unnecessary in the reasoning that I would get rid of.

The result of the Search on the job name with the regex you have specified will be one of the strings in the regex. If none of these strings is present the result is an empty string. So far, so good. You then match it, as correctly suggested by mkayyyy, with a regex, but in that regex you list the same strings again. That is the unnecessary part. It is good enough that the result of the Search is not empty. Conclusion:
[Job.NameProper:Search="(A135.2|A115|C5016|A5012|A5013|B32.2|B33.1|C5010|C5011|C5014|C5015|C5018)"]

Matches

.+

The dot means any character, the plus means that it matches multiple characters, but there must be at least one character! If you do it like this, then you only have to change the left-hand part of the comparison when the list of allowed values changes.

Re: Use regex in condition with variables

Posted: Mon Jan 18, 2021 5:27 pm
by mkayyyy
PdFUser5000 wrote: Mon Jan 18, 2021 3:16 pm Because there are other symbols in the filename, i came up with this. It seems to be working. But is this correct?

[Job.NameProper:Search="(A135.2|A115|C5016|A5012|A5013|B32.2|B33.1|C5010|C5011|C5014|C5015|C5018)"]

Matches

(A135.2|A115|C5016|A5012|A5013|B32.2|B33.1|C5010|C5011|C5014|C5015|C5018)
I'd also recommend updating your RegEx to:

Code: Select all

(A135\.2|A115|C5016|A5012|A5013|B32\.2|B33\.1|C5010|C5011|C5014|C5015|C5018)
That's if you actually want the RegEx to actually match a . character. The . character by itself matches any character (including newline).

I would personally format the condition as below as I find it a easier to follow:

Image

Re: Use regex in condition with variables

Posted: Mon Jan 18, 2021 7:44 pm
by PdFUser5000
Thanks everybody for the feedback! I will try out both versions.