Hello dear Atlassian-Community,
I am currently trying to build something that would make an old automation of mine way shorter and incredibly more efficient, but the whole idea hinges on "being able to create a RegEx dynamically and handing it over to another function"
Here is the functional part of my concept:
0) Trigger: Doesn't matter for this case
1) Action: Create Variable
This is a comma separated gathering of calculations done beforehand. In the real world application this will be provided by a lookupObjects-List-Iteration and (hopefully clever) replace-functions.
Name: myVarInput
Value: 1~A, 111~B, 1~C, 11~D
Worth noting: "More 1 = more important" I would want to get "B" back in some way and i thought of trying with regEx.
2) Action: Create Variable
Name: maxOnesMinusOne
Value: 2
We will not talk about how I will get the max size / maximum numbers of "1"s from {{myVarInput}} here and subtract 1 - lets just assume I get the Value 2 somehow 
EDIT: I have found and shared a way to extract this value in the comments. I still feel it remains out of scope here but for anyone there now exists two-create-variable-steps solution that doesn't even require any RegEx to work. Crazy, I know.
3) Action: Create Variable
Name: myDynamicBlock
Value: [1]\{1,{{maxOnesMinusOne}}\}
Note: I would want to have the output [1]{1,2} for our example input
4) Action: Create Variable
Name: regExTest
Value: {{myVarInput.replace(myDynamicBlock,"0")}}
Note: Following our example line, I would want to have the output 0~A, 01~B, 0~C, 0~D here.
5) Create Variable Action with Further refinement (out of scope for this question, because it only requires a "fixed" RegEx at this point):
Next step would be {{regExTest.split(", ").remove("0~.*")}} (RegEx test pending) to have only the most important (multiple possible) entries left.
Questions:
1) Is the handover from maxSizeMinusOne to myDynamicBlock possible (can i exclude curly brackets somehow)?
2) Is the handover from myDynamicBlock to regExTest possible? (how do i get it to execute properly)
Edit/carifications:
- {{myVarInput}} is vastly reduced in complexity and simply gauging the size of the individual chunks separated by commas will not work in the real world application.
- I have corrected some spelling/consistency mistakes after posting
- Upon some further investigation, I have found this post with an answer related to my musings from @Bill Sheboy - Solved: Jira automation - using variable in another variab... maybe there is indeed some hope for me?
- the 4th action initially and wrongs used {{myVar.replace[...] instead of {{myVarInput.replace[...] - i have adjusted this to avoid confusing anyone reading or trying to reproduce this in the future. Thanks to everyone for noticing!
Kind regards,
Ludwig