Regex optional condition in replace

60 views Asked by At

Input :

abc-AA-abc
abc+AA+abc
AA-abc
AA+abc

Output:

abc-{AA}-abc
abc+{AA}+abc
{AA}-abc 
{AA}+abc

I want to wrap AA when it is in between 2 special characters or when it is in the beginning of the string followed by a special character.

I am able to write regex to match the string using below:

Replace("((\W)(AA)(\W))|((AA)(\W))", "$1{$2}$3").

Above is working fine for first case. But its failing when the match is found at the beginning of the string.

0

There are 0 answers