You need to sign in to do that
Don't have an account?
LALALA
regex code problem
Hi, i have a problem about regex, i spend lots of time on it but still didn't solve it. please any one can answer my question.
this is my part of code:
try{
String myPlainText= 'Order Number: 2000157 Date Ordered: Wednesday, May 21, 2014 City: Auckland, 2241 State/Province: North Island, New Zealand Phone: 021735562';
Pattern p=Pattern.compile('(?=:)*\\d{7}');
Matcher m = p.matcher(myPlainText);
if(m.matches())
{
system.debug(m.group(1));
}
// New orderRecord object to be created - set CustomerEmail__c and OrderNumber__c to
OrderRecord__c record = new OrderRecord__c(CustomerEmail__c = email.fromAddress, CustomerName__c='NINI',
OrderNumber__c =Integer.valueOf(m.group(1)));
insert record;
problems: i use this code to try to extract some data from email, but failed lots of time.
I wanna use regex to extract 2000157 which is order number. but i think my regex are incorrect, so could you help me to fix it? and i can't get value of m.group(1);
this is my part of code:
try{
String myPlainText= 'Order Number: 2000157 Date Ordered: Wednesday, May 21, 2014 City: Auckland, 2241 State/Province: North Island, New Zealand Phone: 021735562';
Pattern p=Pattern.compile('(?=:)*\\d{7}');
Matcher m = p.matcher(myPlainText);
if(m.matches())
{
system.debug(m.group(1));
}
// New orderRecord object to be created - set CustomerEmail__c and OrderNumber__c to
OrderRecord__c record = new OrderRecord__c(CustomerEmail__c = email.fromAddress, CustomerName__c='NINI',
OrderNumber__c =Integer.valueOf(m.group(1)));
insert record;
problems: i use this code to try to extract some data from email, but failed lots of time.
I wanna use regex to extract 2000157 which is order number. but i think my regex are incorrect, so could you help me to fix it? and i can't get value of m.group(1);
It is not going to match because you arent matching the whole string, just looking for the subgroup. I tested that change and it is working for me.
All Answers
can anyone give me a right code?
thanks thanks@!!!!!
Illegal character sequence '\d' in string literal.
Apex wants double slashes for some reason.
It is not going to match because you arent matching the whole string, just looking for the subgroup. I tested that change and it is working for me.