You need to sign in to do that
Don't have an account?
Clay Ashworth
REGEX Help
I am looking for a little guidance on my REGEX statement for a Patter/Matcher Class that extracts a specific string from the body of a plain text email.
The desired match should be as follows:
REF#:xxxx
where xxxx represents a 4 digit number
Here is a sample of the email body I am attempting to parse with a while loop using the matcher:
Below is a Code Sample of the Patter and Matcher portion of the Class. The intent being to find a match to the desired string 'REF#:xxxx', strip out only the number portion of the string and then do a SOQL query against a customer object ServiceLineItem__c. where the field Disconnect_Ticket__c can be updated with a variable derived earlier in the class (ticket) and then added to a list of SObjects for a bulk update.
I am having difficulty getting the REGEX to match the desisred string and could use some assistance.
Thx
The desired match should be as follows:
REF#:xxxx
where xxxx represents a 4 digit number
Here is a sample of the email body I am attempting to parse with a while loop using the matcher:
Wed Dec 10 10:46:59 2014: Request 68000 was acted upon. Transaction: Ticket created by cashworth Queue: New Orders Subject: Service Disconnect Ticket: Test Account LLC Owner: Nobody Requestors: cashworth@somedomain.net Status: new Requestor: Clay Ashworth <cashworth@somedomain.net> CustomField.{Customer Number}:TES002 Service Items for Termination: Ref#:0000 Product: Test Product Quantity: 1 Total MRC: 0.00 Item Description: test product Service Location(s): Some Location Test Last Date of Service: 2014-12-31 00:00:00
Below is a Code Sample of the Patter and Matcher portion of the Class. The intent being to find a match to the desired string 'REF#:xxxx', strip out only the number portion of the string and then do a SOQL query against a customer object ServiceLineItem__c. where the field Disconnect_Ticket__c can be updated with a variable derived earlier in the class (ticket) and then added to a list of SObjects for a bulk update.
//Pattern-Matcher to find ref numbers Pattern RefP = Pattern.compile('REF#:[0-9]{4}'); Matcher RefM = RefP.matcher(email.plaintextbody); //Loop through the matches while (RefM.find()) { ref = RefM.group().right(4); system.debug(ref); //Build list of Service Line Items with ref numbers and Lookup ref numbers and update with ticket number if(ref != null) { ServiceLineItem__c sli = [select Id, CIS_Id__c from ServiceLineItem__c where CIS_Id__c = :ref limit 1]; if(sli != null) { sli.Disconnect_Ticket__c = ticket; sliList.add(sli); } } } } //Update the Service Line Items with the disconnect ticket number if(sliList != null) { update sliList; }
I am having difficulty getting the REGEX to match the desisred string and could use some assistance.
Thx
Pattern RefP = Pattern.compile('Ref#:[0-9]{4}');