Variable substitution inside Regular Expression.

Hi Gurus,

I am using Branch with Regular expression.

Code :

Two variables in pipeline.
testStr = abc
validStrList = abc|xyz|efg
BRANCH - Evaluate Label = False, Switch on /testStr
SEQUENCE - Label = /%validStrList%/

As you can see I would like to peform variable substitution before evaluation the regular expression. This is not working.

If I hard code values of validStrList in regular expression it works.

Has any one tried this? Or any other suggestions, workarounds??

Appreciate your help.
Ajit

When you are doing a variable substitution you need to set the Evaluate Label to True.

Ajit,

Try this:
In addition to your to your testStr and validStrList create another var evaluateStr and set its value to the expression that you want to evaluate, ie hardcode %testStr% == /%valStrList%/ into evaluateStr and check mark ‘Perform Variable Substitution’ when hardcoding the value. Now create your branch as follows:

Branch [Evaluate Label = True]
– Sequence [Label = %evaluateString%]
---- Do your stuff here
– Sequence [Label = $default]

Hope this helps

~ Rohit

Thanks Rohit and altgecko,

I was very much convinced with Rohit’s solution, but its not working either…

I tried it. I dont think we can put regular expression with variable substitution…

Rohit can you please give it a quick go… It alwas goes in first sequence cause lable %evaluateString% means if evaluateString exist or not null then go in… and it does exist as "abx == /abc|xyz|efg/ " I also tried with value of evaluateString = “/abc|xyz|efg/”, still dont work…

I believe for Regular Expression we have to use evalute label equal to false but then we can not do variable substitution to have regualar expression dynamic…:frowning:

:frowning:

Thanks…

My bad! Yes it goes to the first sequence because the var evaluateString exists in the pipeline. Hmmm I tried it many other ways but nothing seems to be working.

I think you’ll need to use other ways of determining whether your input var (testStr) is valid or not - you know, by tokenizing valStrings, looping over tokens and then branching… unless u find a way of doing this. If so please do share it with us.

~ Rohit

Thanks Rohit,

I know the tokenizing way to doing it… I am already doing it at some other place but I believe it will be bit expesive than regular expression… But doesnt look like there is any other way…

Thanks for your inputs guys… Atleast its clear now…

Cheers,
Ajit

Perhaps I’m not understanding the problem correctly, but I think you can do this using PSUtilities, as long as you’re running at least JVM 1.4. Before you do your BRANCH, call PSUtilities.regex:matches and map testStr to ‘input’ and validStrList to ‘regex’. Then BRANCH on the value of ‘match’ (true or false) to decide which sequence to take. HTH,

Tim

Thanks Tim,

PSUtilities.regex:matches service did the job. Apologies for troubles guys. I should have checked PSUtilities before hand…

Ta,
Ajit

Variable substitution is not supported for regular expression in branch step. i had to wrote a small java service using java.util.regex.* for building my own rule engine.

Advantage site also listed this problem as unsupported.
[url]https://advantage.webmethods.com/advantage?targChanId=kb_home&oid=1613807838[/url]

Thanks
Ravi

I had some similar requirement where I had to substitute a pipeline variable in regex pattern .

I added a map step for substituting the pipeline variable in regex pattern and then passed it to PSUtilities.regex:matches