+ Start a Discussion
LALALALALALA 

Why? Why No Match Found From Email?

This is my code:
global class ExtractDataFromPaypal implements Messaging.InboundEmailHandler {

    global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,

    Messaging.InboundEnvelope env) {

        // Create an InboundEmailResult object for returning the result of the  

        // Apex Email Service 

        Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

        try {

            // Add the email plain text into the local variable  

             string myHtmlText = '';

             myHtmlText = email.htmlBody;

            

            string rst;

            string Address;

            string a1;

            string a2;

            

            //CustomerName

             Pattern p4 = Pattern.compile('Buyer\\s*information[\\s\\S]+?<br>([\\s\\S]*?)</font>');

            Matcher m4 = p4.matcher(myHtmlText);

            if (m4.find()) {

             rst = m4.group(1).replaceAll('(<[^>]*>)','');          

            }

            

            //Physical Address

            Pattern p1 = Pattern.compile('<b>\\s*Ship-to\\s*address\\s*</b>\\s*-\\s*<font[^>]+>\\s*Confirmed([\\s\\S]*?)<br>\\s*</span>');

            Matcher m1 = p1.matcher(myHtmlText);

            if (m1.find()) {

                a1 = m1.group(1).replaceAll('(<[^>]*>)',''); 

                a2 = a1.replaceAll('&nbsp;','\t');

                Address = a2.replaceAll(rst,'');

            }

            // New PaypalRecord object to be created - set Shipping_Address__c and OrderNumber etc. to object

            // dummy values for simplicity

            PayPal_Record__c record = new PayPal_Record__c(CustomerName__c = rst, Shipping_Address__c = Address

                                                    );

            // Insert a new record

            insert record;

    

        } catch (Exception e) {

            result.success = false;

            result.message = 'Oops, I failed!' + e;

        }

        // Set the resul t to true. No need to send an email back to the user      

        // with an error message   

        result.success = true;

        // Return the result for the Apex Email Service 

        return result;

    }

}


So my problem is : when i debug this code, everything is fine, it can running successfull and all the data i grabed from email can entry in database,,,,,but when i running in real environment which i use email service,,,,,, then i will received an email and told me : 
Oops, I failed!System.StringException: No match found

why?   please give me some idea and suggestion.
Thank you anyone who can help me.....:)
NagaNaga (Salesforce Developers) 
Hi Sales Manager,

During a matching operation, each substring of the input string that matches the pattern is saved. These matching substrings are called capturing groups. 

Capturing groups are numbered by counting their opening parentheses from left to right. For example, in the regular expression string ((A)(B(C))), there are four capturing groups:

((A)(B(C)))
(A)
(B(C))
(C)

Group zero always stands for the entire expression.

The captured input associated with a group is always the substring of the group most recently matched, that is, that was returned by one of the Matcher class match operations. 

If a group is evaluated a second time using one of the match operations, its previously captured value, if any, is retained if the second evaluation fails.

Please follow the below link for more info

http://www.kineticgrowth.com/salesforce-apex-regex-capturing-groups-regular-expressions/

Best Regards
Naga Kiran