Hello, i am new to regular expressions and using regexprep as well. I want to write a function which replaces names of variables with a given new name. The expression i used first was (^|\W)oldName(\W|$) and $1newName$2 as the replacement.
Unfourtunatly this will not replace expressions like variableA*variableA or variableB+variableB. The second factor or summand is not replaced so i have to do regexp() twice. Secondly i tried the expression (^*|\W)oldName(\W|$) which will replace the second factor in the example above, but will also replace the name in something like this: thisvariableA.
matchPattern = (^|\W)oldName(\W|$);
replacePattern = $1newName$2;
StringContent = 'oldName*oldName';
ContentNew = regexprep(StringContent , replacePattern , matchPattern);
So i am looking for a regexp pattern which matches 'oldName' also after an operator which follows after and before'oldName'. A way to match the given example would help.