Variable in Regex Pattern


How to add variable in the pattern of regex? I am looking through email body to find a price of an item and it works if I test it with specific item. But I need it to work with a variable as the item will be a different each time. At the moment just testing with some random string

when I use following pattern (?:someitem)\s+[\w ]+\S*\d+\S* it works fine but when adding the variable ‘newtext’ it will not work.

Any suggestions?


Assign your pattern as a string before hand then pass the whole variable as the pattern

1 Like

Thanks Tim. I found that the way I wrote the pattern was an issue “(?:”+newtext+“)\s+[\w ]+\S*\d+\S*” seem to work .

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.