I'm working on regex in order to replace some strings
public static String removeValuesByRegex(String input, Pattern pattern, String replaceWith){
String result;
Matcher matcher = pattern.matcher(input);
return result = matcher.replaceAll(replaceWith).trim();
}
Then in my test class im doing
String keywords = 'LLC|Corp|Corporation';
Pattern pattern = Pattern.compile('(?i)(?<= |^)\'|' + keyWords + '\'|(?= |$)');
String stringResult = UtilString.removeValuesByRegex('Corporation This Has a Name LLC AND CoRp ', pattern, '');
The output will come out as
oration This Has a Name AND
What appears to be happening is the regex is finding Corp in Corporation and removing "Corp" which then messed up the the Corporation comparison, is this a regex update or can I not do this approach?