AF
Home
Tag
Submit Notes
Ask Anything
Login
Subscribe Us
A
ny
F
orum
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.
Follow @anyforumin
programming-regex: regular expression for parsing sms
i want regular expression for parsing sms from justdial that in following format
7, mr amol +919049987696, +912066056700 enquired for e learning software solutions for school in hadapsar - justdial
some like following
(sms id,name mobile no1,mobile no2,,,mobile no n enquired for any string)
i want fetch sms id,name ,mobile nos and string after "enquired for"
programming x 169
regex x 7
Posted On :
2017-07-14 20:49:38.0
rahul patil
42
-3
0
4
Answers
I think we can use regex for extracting and replacing the phone numbers. Rest thing we can manipulate it using simple String class methods. Please check below code snippet.
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexParser {
public static void main(String[] args) {
String input="7, mr amol +919049987696, +912066056700 enquired for e learning software solutions for school in hadapsar - justdial";
String phoneNumberRegex="\\+\\s*(\\d+)";
String[] inputArray=input.split("enquired for ");
String[] idNameArray=inputArray[0].split(",");
System.out.println("SMS ID: "+idNameArray[0]);
System.out.println("Name: "+idNameArray[1].replaceAll(phoneNumberRegex, "").trim());
Matcher matcher = Pattern.compile(phoneNumberRegex).matcher(input);
System.out.println("Phone Numbers: ");
while (matcher.find()) {
System.out.println("+"+matcher.group(1));
}
System.out.println(inputArray[1].replaceAll(" - justdial",""));
}
}
Posted On :
2017-07-14 23:51:36
Satisfied :
1 Yes
0 No
Rishi Kumar
523
1882
49150
Reply This Thread
3
Post Answer
Please Login First to Post Answer:
Login
Answer:
anyforum.in