Hi,
i have 3 possible scenarios. how do you extract the name and telephone into variables each?
1st scenario
Mr Donald Duck +91 8586 077606
2nd scenario
Mr Mickey 9123 4567
3rd scenario
Miss Sponge Bob 61234567
Hi,
i have 3 possible scenarios. how do you extract the name and telephone into variables each?
1st scenario
Mr Donald Duck +91 8586 077606
2nd scenario
Mr Mickey 9123 4567
3rd scenario
Miss Sponge Bob 61234567
Hi,
Can you try the following?
Name : System.Text.RegularExpressions.Regex.Split(strData,"(?<=[A-Za-z])\s(?=[+\d ])")(0)
Telephone : System.Text.RegularExpressions.Regex.Split(strData,"(?<=[A-Za-z])\s(?=[+\d ])")(1)
FYI, You can get string array like {name, telephone} using System.Text.RegularExpressions.Regex.Split(strData,"(?<=[A-Za-z])\s(?=[+\d ])")
Regards,
Hi
Kindly try with this expression if the input is in variable named str_input
—to get the number
str_number = System.Text.RegularExpressions.Regex.Match(str_input,”[\s][\W0-9]+”).ToString.Trim
And for name
str_Name = System.Text.RegularExpressions.Regex.Match(str_input,”(?<=Mr).+(?=\s\W\d)|(?<=Mr).+(?=\s\d)|(?<=Miss).+(?=\s\d)|(?<=Miss).+(?=\s\W\d)”).ToString.Trim
Cheers @kelvinyeo24
Hi,
thanks, yes it works!
If it is a sentence, how to extract the name and contact? for example;
The customer is Mickey Mouse and he can be reached at 9123 4567
Yah for name like this
System.Text.RegularExpressions.Regex.Match(str_input,”(?<=The customer is ).*(?= and)”).ToString.Trim
For number
System.Text.RegularExpressions.Regex.Match(str_input,”[\s][\W0-9]+”).ToString.Trim
Cheers @kelvinyeo24
Hi,
Name : System.Text.RegularExpressions.Regex.Match(strData,"(\s[A-Z][a-z]+)+").Value.Trim
Telephone : System.Text.RegularExpressions.Regex.Match(strData,"[+\d][\d ]*").Value.Trim
(In case that there is no Name at the beginning of the sentence)
Regards,
just curious how it works? how does it know mickey mouse is the name?
Hi,
It is based on whether the first letter of a word is capitalized. However, we can’t tell the difference from the sentence head just by that, so it’s also checked if there is a blank or not before the word.
Regards,
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.