How to Use Variables in RegEx expression?

Dears,

I’m using one RegEx Expression to get desired words from text that contains A2 and B2 characters : \S*(A2|B2)\S*, but sometimes this value is changing from document to another, How to make this value “A2|B2” as variable in RegEx expression ?

Thanks in advance

@hsendel - Please check this…

 "\S*"+StrVar+"\S*"

Here StrVar = “fo”

Here is my output

OR

"\S*("+StrVar+")\S*"

Here StrVar = “fo|in”

you can use two different variables fo or in , as per your wish

Hope this helps…

1 Like

Thanks a lot @prasath17 , it was very easy to modify expression in pattern rather than RegEx editor, I miss that :slight_smile:

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