Use regex in condition with variables

Post Reply
PdFUser5000
Member
Posts: 120
Joined: Fri Jun 12, 2020 11:23 am

Use regex in condition with variables

Post 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 5310 times
Attachments
Capture1.PNG
Capture1.PNG (27.82 KiB) Viewed 5311 times
mkayyyy
Member
Posts: 75
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: Use regex in condition with variables

Post 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
PdFUser5000
Member
Posts: 120
Joined: Fri Jun 12, 2020 11:23 am

Re: Use regex in condition with variables

Post 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)
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Use regex in condition with variables

Post 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.
mkayyyy
Member
Posts: 75
Joined: Mon Nov 21, 2016 6:31 pm
Location: UK

Re: Use regex in condition with variables

Post 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
PdFUser5000
Member
Posts: 120
Joined: Fri Jun 12, 2020 11:23 am

Re: Use regex in condition with variables

Post by PdFUser5000 »

Thanks everybody for the feedback! I will try out both versions.
Post Reply