New answers tagged

0

If you have a limited number of special characters to replace... Assuming the field is called Phone__c SUBSTITUTE( SUBSTITUTE( SUBSTITUTE( SUBSTITUTE(Phone__c,'-',NULL), '_',NULL), '(',NULL), ')',NULL) Removes hypen, underscore, left and right parens. Extend to other common characters like period/dot, plus sign, blanks, etc. If I enter (650)555-1212 I ...


1

Just adding another option here: you can utilize some great playground tools to figure it our or test out your regex before putting it into your code. https://regexr.com/ and then a great resource for learning regex as well https://regexone.com/


2

Try String r = t.replaceAll('[-%/.<>&:]',' '); // Put all your symbols here. Example: String t = 'I-am%Noor/who/are:you<I>am'; String r = t.replaceAll('[-_%/."<>&:()!/*/^]',' '); System.Debug(r); Output: I am Noor who are you I am


3

It's a rather complex Regex but here's one that works: ((?!00)[0-3][0-9]\/(?!00)[0-1][0-9]\/(?!0000)[0-9]{4}(?![0-9])\R?)+ Here's some sample data: 07/12/1985 30/01/1986 12/07/2016 01/09/2019 You can try it out regex101.com. And here's how to test that in apex: Boolean matches = Pattern.matches('((?!00)[0-3][0-9]\\/(?!00)[0-1][0-9]\\/(?!0000)[0-9]{4}(?!...


0

As per the documentation, REGEX applies Java's regex handling. This means you can use "\n" (actually done using "\\n" as per the documentation) to match new line. Try something like (simplified): "([0-9]{1,2}/[0-9]{1,2}/[0-9]{4}\\n)*[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}(\\n)?" This should allow zero or more dates with new lines followed by a single date ...


Top 50 recent answers are included