AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
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 ?.



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 136
regex x 5
Posted On : 2017-07-14 20:49:38.0
profile rahul patil - anyforum.in rahul patil
34-30
up-rate
4
down-rate

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
profile Rishi Kumar - anyforum.in Rishi Kumar
523185518077
Reply This Thread
up-rate
3
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in