Building a regular expression with a variable?

Post Reply
blingen
Newbie
Posts: 6
Joined: Thu Mar 31, 2022 12:43 am

Building a regular expression with a variable?

Post by blingen »

Is it possible to use a variable inside a regular expression, or to use a single variable for an entire regex? In other words, I'm trying to build up a regex dynamically, depending on incoming jobs. For example, let's say I've got 3 different folder elements that each set a private data key:

Folder 1
Set job private data:

Code: Select all

Pattern=(one|two)
Folder 2
Set job private data:

Code: Select all

Pattern=(three|four)
Folder 3
Set job private data:

Code: Select all

Pattern=(five|six)
Now each of those folders leads to a single destination, which is an element with a regex property (like Inject Wildcard or Scan Hierarchy). Regex syntax already uses square brackets ([]) like Switch's variables, so something like this probably wouldn't work:

Define regular expression:

Code: Select all

Example_[Job.PrivateData:Key="Pattern"].pdf
Intended result possibilities depending on job:

Example_(one|two).pdf (match Example_one.pdf or Example_two.pdf)
Example_(three|four).pdf (match Example_three.pdf or Example_four.pdf)
Example_(five|six).pdf (match Example_five.pdf or Example_six.pdf)


I don't think I could use simple filters because ? and * wildcards aren't enough for what I need to match. My alternative is to have, for example, 3 entirely separate Scan Hierarchy elements for each of the incoming folders, but having only 1 would keep things easier to maintain.
Post Reply