Extract numeric from given string

I have few strings like follows,

Str1 = abc, xyz.tucr@pqr.com 123-456-7890
str2 = abc, xyz.tuck@pqr.com +61 123 321 222
str3 = abc - DEF jke@xyz.com (404) 123-1111 ext. 4444

I want to get only numeric (Phone numbers) out of these strings. i.e : 123-456-7890 +61 123 321 222
(404) 123-1111 ext. 4444

Can anyone provided me regular expression for the same or any other way to do this.

Thanks,

@Mangesh_kulkarni Follow below link

How to split a string in uipath by using Regular Expression - #6 by indra

Hi… Try this…
(str1.Split("@“c).ElementAt(1).ToString.Trim).Remove(0, str1.Split(”@“c).ElementAt(1).ToString.Trim).Split(” "c).ElementAt(0).Length+1)

I am a noob at expressions but that works here when I was testing.
I can try to explain, but I am not native english speaker and I may embarrass trying.

1 Like

Hi @Mangesh_kulkarni,

Use regex

Pattern: (?<=.com ).*

Regards,
Arivu

1 Like

If your input strings will always be in this format, the regex expression provided above (i.e. (?<=.com ).*) shall work just fine.

IF the position of the phone numbers can change in the input string, the above regex WON’T work.

In that case, you first need to figure out all possible phone-number patterns, For the ones mentioned above, here’s the regex (which does seem complex, but it’ll do the job):

(\d{3}(-)?\d{3}(-)?\d{4})|(+\d{2}\s?\d{3}\s?\d{3}\s?\d{3}\s?)|((\d{3})\s?\d{3}(-)\d{4}\s?(ext.)\s?\d{4})

Try this Regex match:

Integer.Parse(Regex.Replace(x, "[^\d]", ""))

Revert back if you don’t know how to use Regex in UiPath

3 Likes

Thanks !! It worked for me

Hello guys,

I have following string:

String str= "COO OPP (404) 851-1331 ext. 1520 "

I want to get result as (404) 851-1331 ext. 1520 like this by using regular expression only.
Can anyone provide me exact regular expression for the same.

Thanks,

@Raguvarthan i really dont know how to use regex
my input is (1) i just want 1 out of it i used below but still am getting zero

System.Text.RegularExpressions.Regex.Replace(“iCheck”,"\D","")

If each string has " *.com ", why not using String.Split(“com”)(1) to get your target?

Instead of using regular expression, I would suggest to use split activity either on the basis of or keyword ext. that is a part of your string