Regex Matcher In Apex : Biswajeet

Regex Matcher In Apex
by: Biswajeet
blow post content copied from  Biswajeet Samal's Blog
click here to view original post

The blow code is replacing the SSN number with * from a sentence.

Sample Code:

String searchText = 'This is your SSN 000-45-6789 number';
Pattern objPattern = Pattern.compile('[0-9]{3}-[0-9]{2}-[0-9]{4}');
String result = objPattern.matcher(searchText).replaceAll('***-**-****');
System.debug('searchText-' + searchText);
System.debug('result-' + result);

December 08, 2022 at 05:15PM
Click here for more details...

The original post is available in Biswajeet Samal's Blog by Biswajeet
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.