I want to match those substrings which have the $
character in below lines.
They all should be replaced with TEST
. They are not necessarily between quotations (""
) or $
and are not necessarily at the beginning of those substrings.
I guess those which are not between "" could be delimited by =
, ;
,or ,
What could be the simplest regex to achieve this?
CACCALLPLC: CALLPLCNAME="${EPolicyCacName}", MCB=$BANDWIDTH;
CACPLCSET: CACPLCSETNAME="${BandPolicyName}",ACPLCSETMODE=SHARE,ALLPLCNAME="${EPolicyCacName}";
SIPAN: ANNAME="E_$BackupCorporateName", LETYPE=P-CSCF, ADDRNAME="$ADDRNAME";
Expected result:
CACCALLPLC: CALLPLCNAME="TEST", MCB=TEST;
CACPLCSET: CACPLCSETNAME="TEST",ACPLCSETMODE=SHARE,ALLPLCNAME="TEST";
SIPAN: ANNAME="TEST", LETYPE=P-CSCF, ADDRNAME="TEST";
You can do something in the lines of this [^"=]*\$[^;",]*
This will try to look for a match, through a few steps.
[^"=]*
- Looks for 0 to unlimited characters not "
or =
\$
- Looks for the character $
[^;",]*
- Looks for 0 to unlimited characters not ;
, ,
or "
This will try to look for a $
in the middle of some delimiters. You can then replace the matches with TEST
Example of this on regex101