function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
girbot56girbot56 

ReplaceAll Help - Replace String with a Mask

Hi all,

I am trying to mask certain details in the body of an email message using regex and the string method replaceall. I've no issue with the regex, I can see it matching and can add a value to the body with a match. However I have not been able to replace the matched substring, this is what I am trying at the moment:

String mask = '*';
String embody = 'Test text body 1111 test';

Pattern p = Pattern.Compile('(\\d{4})'); //simplified
p.matcher(em.TextBody).replaceAll(Mask);
As I mentioned I am confident that the regex is matching by using debug comments and I have updated the field on a match but I cannot get replaceall to work :(

What I am missing?


girbot56girbot56
In case it is relevent I am trying to use a before insert trigger
Ramu_SFDCRamu_SFDC
The below post have examples and descriptions, please see if this helps

http://salesforcesource.blogspot.in/2010/01/utilizing-apex-pattern-and-matcher.html
girbot56girbot56
I'm not sure if does...I have no issue with matching but not having much luck with replaceall actually doing anything. I'll try using the last example as a source (for completeness below):

string html = 'your html code';
 //first replace all <BR> tags with \n to support new lines
string result = html.replaceAll('<br/>', '\n');
result = result.replaceAll('<br />', '\n');

//regular expression to match all HTML/XML tags
string HTML_TAG_PATTERN = '<.*?>';

// compile the pattern     
pattern myPattern = pattern.compile(HTML_TAG_PATTERN);

// get your matcher instance
matcher myMatcher = myPattern.matcher(result);

//remove the tags     
result = myMatcher.replaceAll('');