tag:blogger.com,1999:blog-5277328648605741474.post5452143958417863160..comments2024-03-19T08:13:51.196-04:00Comments on Salesforce <Source>: Utilizing Apex Pattern and Matcher ClassesSam Arjmandihttp://www.blogger.com/profile/03304120460251140274noreply@blogger.comBlogger18125tag:blogger.com,1999:blog-5277328648605741474.post-37821071783042836982013-09-05T08:23:18.136-04:002013-09-05T08:23:18.136-04:00I have To append a hardcoded text on an RE how can...I have To append a hardcoded text on an RE how can i do this <br /><br />Example<br /><br />Test Date 2012-2-3<br />Test Date 2011-4-5<br />...<br /><br />I have to append "Test Date" in my date RE, how can i accomplish this Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-87189718034568503152013-02-25T05:33:03.913-05:002013-02-25T05:33:03.913-05:00how to avoid names like 'a namika' or...how to avoid names like 'a namika' or 'a......nnu' in text field Can u plz tell me the regex of this.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-17203893012030261992012-03-08T20:58:01.081-05:002012-03-08T20:58:01.081-05:00In addition to this, I've read your other arti...In addition to this, I've read your other article on GoogleCharts. Thank you very much for sharing your knowledge.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-30262251445029142032011-09-16T04:23:16.473-04:002011-09-16T04:23:16.473-04:00help in validate a number with single "-"...help in validate a number with single "-"Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-1898439657839817252011-08-07T08:04:07.217-04:002011-08-07T08:04:07.217-04:00Akhilesh Soni, Java documention says about matches...Akhilesh Soni, Java documention says about matches():<br />"Attempts to match the entire region against the pattern".<br /><br />So in you case it's always false, because 'PO' (the whole string) is not a letter between A-Z.Itaynoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-15592932293817072452011-07-10T22:39:31.139-04:002011-07-10T22:39:31.139-04:00Hey Sam ,
Is there anything wrong with the followi...Hey Sam ,<br />Is there anything wrong with the following code segment, i m always getting "invalid" :-(<br /><br />String InputString = 'PO';<br />String emailRegex = '[A-Z]';<br />Pattern MyPattern = Pattern.compile(emailRegex);<br />Matcher MyMatcher = MyPattern.matcher(InputString);<br />if (!MyMatcher.matches()) {<br />system.debug('-------- invalid'); <br />}<br />else{<br />system.debug('-------- valid'); <br />}Akhilesh Sonihttps://www.blogger.com/profile/16308020464292348231noreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-22857900107431513462011-03-15T08:55:48.438-04:002011-03-15T08:55:48.438-04:00Have you found a way to use the Pattern flags like...Have you found a way to use the Pattern flags like you can with Java? Everytime I try to use a flag like Pattern.MULTILINE I get a variable does not exist error.Patrickhttps://www.blogger.com/profile/11999290356494821136noreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-6885122474111287852011-01-08T03:42:08.166-05:002011-01-08T03:42:08.166-05:00Sam,
I have not been successful in using split fun...Sam,<br />I have not been successful in using split function on the matcher object as documented here http://download.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html#split(java.lang.CharSequence, int)<br />Do you know if there is a workaround?<br /><br />My use case is, I have an email chain and am trying to identify the second occurrence of 'From:'. If I had split function then I can split the email chain into two.<br /><br />Thanks in adv<br />SKAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-22440492711576654652010-10-15T11:47:06.512-04:002010-10-15T11:47:06.512-04:00Two things you may want to consider:
Prepend your ...Two things you may want to consider:<br />Prepend your regular expression with (?i) to make the match case-insensitive so to ensure that any html br tags that are in caps are also replaced:<br />result = result.replaceAll('(?i)<br>', '\n');<br /><br />To match br tags that are and are't self closing, and match any arbitrary number of spaces inside the tag:<br />result = result.replaceAll('(?i)', '\n');<br /><br />Regular expressions are very... exacting. Also, if you want to do anything more complex than this with an html document, you should probably use a language parser rather than regular expressions because regexes can't readily describe a language grammar well enough to eliminate all edge cases.Unknownhttps://www.blogger.com/profile/04677761388146716272noreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-92228169572588034602010-10-06T22:00:36.688-04:002010-10-06T22:00:36.688-04:00Sam - thank you so much for posting this! A wealt...Sam - thank you so much for posting this! A wealth of information for a novice like me! :)Leenanoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-46350841783777812272010-09-01T11:42:53.898-04:002010-09-01T11:42:53.898-04:00Hi Sam this might be what I was looking for...we h...Hi Sam this might be what I was looking for...we have an Apex class in salesforce to process email body into fields, but it only processes plain text emails. We have an HTML email which gives an error. If we use your HTML stripping code will this covert the HTML to plain text and then process email correctly?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-21030172388537046592010-06-25T13:06:58.677-04:002010-06-25T13:06:58.677-04:00Oh, wait... there's a space between the r and ...Oh, wait... there's a space between the r and slash so the replacements aren't the same. NeverMind!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-18690081679507310702010-06-25T13:06:45.301-04:002010-06-25T13:06:45.301-04:00The first and second statements have a slight diff...The first and second statements have a slight difference to cover the scenario where the HTML developer have a space between the "BR" and the closing tag.Sam Arjmandihttps://www.blogger.com/profile/03304120460251140274noreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-10065304132438730502010-06-25T13:04:53.969-04:002010-06-25T13:04:53.969-04:00You've already replaced all the br tags with &...You've already replaced all the br tags with "newline" tags in the first statement, right? So why have the second line that makes no change?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-6266448264338730672010-06-25T12:52:48.146-04:002010-06-25T12:52:48.146-04:00This way you can convert the HTML break lines into...This way you can convert the HTML break lines into text "newline" character.Sam Arjmandihttps://www.blogger.com/profile/03304120460251140274noreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-15487904943941293822010-06-25T12:50:29.698-04:002010-06-25T12:50:29.698-04:00in your HTML stripping example why do you need the...in your HTML stripping example why do you need these 2 lines? Won't the first line suffice?<br /><br />string result = html.replaceAll('<br>', '\n');<br />result = result.replaceAll('<br>', '\n');Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-59210314824666321952010-01-14T13:02:35.210-05:002010-01-14T13:02:35.210-05:00I think this might work.
From.*\[mailto:I think this might work.<br /><br />From.*\[mailto:Jasonhttp://www.tehnrd.comnoreply@blogger.comtag:blogger.com,1999:blog-5277328648605741474.post-7343758960410129542010-01-14T12:51:43.960-05:002010-01-14T12:51:43.960-05:00I am really struggling to grasp regular expression...I am really struggling to grasp regular expressions. Is it possible to search a string and find a match for something like this:<br /><br />From: John Doe [mailto:<br /><br />"From:" and "[mailto:" will always be static but "John Doe" could change.Jasonhttp://www.tehnrd.comnoreply@blogger.com