[SalesForce] Replacing Regex Match with Blank space

This should be a simple question, but I cannot find the answer. I need is to replace my Regex Match with blank space. What is the Syntax for this? Here is my Expression:

Matcher alphaSourceMatch = Pattern.compile('(?mi)<\\/?\\w*\\b[^>]*>').matcher(alphaSource);

I would simply like to replace the pattern with ' '.

Best Answer

You just need to append the .replaceAll(' ') method to your Matcher instance to replace every match with a space.

Matcher alphaSourceMatch = Pattern.compile('(?mi)<\\/?\\w*\\b[^>]*>').matcher(alphaSource);
String replacedText = alphaSourceMatch.replaceAll(' ');

Docs: Matcher.replaceAll(string)

Related Topic