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?
Use regex in condition with variables
-
- Member
- Posts: 122
- Joined: Fri Jun 12, 2020 11:23 am
Use regex in condition with variables
- Attachments
-
- Capture1.PNG (27.82 KiB) Viewed 5417 times
Re: Use regex in condition with variables
To use a regular expression as the right-hand side condition you need to use the Matches or Does not match Comparison operators
-
- Member
- Posts: 122
- Joined: Fri Jun 12, 2020 11:23 am
Re: Use regex in condition with variables
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)
[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
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.
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
I'd also recommend updating your RegEx to: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)
Code: Select all
(A135\.2|A115|C5016|A5012|A5013|B32\.2|B33\.1|C5010|C5011|C5014|C5015|C5018)
I would personally format the condition as below as I find it a easier to follow:
-
- Member
- Posts: 122
- Joined: Fri Jun 12, 2020 11:23 am
Re: Use regex in condition with variables
Thanks everybody for the feedback! I will try out both versions.