0

I have being trying to Parse this text properly for a couple days now. I cannot seem to figure out how to collect the text after Traveller name in the following Text:

---------- Forwarded message --------- From: Mai Le Date: Thu, Sep 10, 2015 at 11:32 PM Subject: Inquiry from Mai Le: Sep 26 through 28 - VRBO.com #468160 To: , Congratulations, you have a new inquiry! [image: VRBO from HomeAway] [image: Our Family of Brands] Hello, Mai Le is interested in your property. Property #468160 Dates Available * Sep 26-28, 2015 * , 2 nights Guests 4 adults, 2 children Traveler name Mai Le Traveler email pmaitu@gmail.com Traveler phone + CA 6138842305 Inquiry from HomeAway.com Total rental amount $448.00 including taxes and fees ------------------------------ * Message from Mai Le* Hello, I would like to finalize my booking. Please let me know the best number i can reach you for details. I have 5 adults and 2 small children. Mai ------------------------------ Respond in your dashboard Or, reply to this email Respond quickly to increase your chance of securing the booking. Looking for more inquiries? Listings with a quality score of 80% or greater get 15%* more demand! Follow the customized recommendations in your dashboard now. * Based on internal metrics taken from data on VRBO.com between December 1, 2014 and December 31, 2014 Download the HomeAway app so you can reply to travelers, send payment details, manage your calendar, and more on your mobile device. ------------------------------ [image: Facebook] [image: Twitter] © 2015 HomeAway.com, Inc. All rights reserved. VRBO and the VRBO logos are trademarks of HomeAway.com, Inc. HomeAway.com, Inc. is located at 1011 West Fifth Street, Suite 300, Austin, Texas, 78703. This email was sent to inquiries@niagarasmartstays.com,alex@niagarasmartstays.com. View our Privacy Statement | Contact Us | Terms & Conditions

I need to search for Traveler name using Regex to collect "Mai Le", and paste that into the Lead.Name field on a new lead record. I'm not sure why this isn't working but here is my current regex formula.

Pattern p = Pattern.compile('(?m)(?i)^\\s*name(.*)');
Matcher pm = p.matcher( leadRecord.RichEmailText__c );

if( pm.matches() )
{
     leadRecord.Email_Guest_Name__c = pm.group(1);
}
2

Based on your post you want to get the text that is between 'Traveler name' and 'Traveler email'. This regex will create 3 capture groups. The 2nd capture group will be the name of the traveler.

(?mi)(traveler\s*name)(.*\s*)(traveler\s*email)

  string source = 'asdfsdf asdfsdf Traveler name Mai Le Traveler email asdfasf asdfsadf asdfsf ';

  Matcher m = Pattern.compile('(?mi)(traveler\\s*name)(.*\\s*)(traveler\\s*email)').matcher(source);
     if (m.find()){
        System.debug('Success');
        System.debug(m.group(0));
        System.debug(m.group(1));
        System.debug(m.group(2));
        System.debug(m.group(3));
     }
2
  • Thank you this has taken me very far in my project! Although when I try to retrieve the phone number in the same fashion, it does not run as expected. Example: (?mi)(traveler\\sphone)(.*\\d)(inquiry\\sfrom\\sHomeaway\\.com). This regex captures everything between the 1st and 3rd capture groups (including "+ CA"). Should it not only capture numbers between the 1st and 3rd capture groups? Sep 12 '15 at 2:02
  • You need to account for the white space between the number and 'inquiry'. Your expression will only match if there is no space 6138842305Inquiry Sep 13 '15 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.