Regex to retrieve phone number and address

Hi friends,

I need to scrap address, phone number and operation hours on daily basis separately from the group of below strings. Could someone help me on this?

“1111MiStreetSanFrancisco,CA44000,USA 222-4444-1111 Hours Sunday 9:00AM-8:00PM Monday 7:00AM-9:00PM Tuesday 7:00AM-9:00PM Wednesday 7:00AM-9:00PM Thursday 7:00AM-9:00PM Friday 7:00AM-9:00PM Saturday 8:00AM-9:00PM”

I need address field with the value “1111MiStreetSanFrancisco,CA44000,USA”

Phone Number field = “222-4444-1111”

Sunday = “9:00AM-8:00PM”, Monday, Tuesday for all the days in separate field or variable


Hi Friends,

I am able to capture separately using regex but it does not work if i group everything.

For hours - (\d:00AM-\d:00PM) - It highlights all the opening hours

For phone number - image

For address - (.+?USA)

I don’t know how to group them together all the required values. Could anyone help me now?



You might consider using just a Split()

address = str.Split(" "c)(0).Trim
phone = str.Split(" "c)(1).Trim
sundayHours = Split(str,"Sunday")(1).Trim.Split(" "c)(0).Trim
mondayHours = Split(str,"Monday")(1).Trim.Split(" "c)(0).Trim
tuesdayHours = Split(str,"Tuesday")(1).Trim.Split(" "c)(0).Trim

this should work if your string is in a consistent format.

If you still prefer Regex, can you upload a .txt file of the string? That way we can test the pattern on the string.


@Boopathi Can you confirm every time format will be same or different

Hi @indra yes time format remains same.


Hi @claytonM string remains consistent but empty spaces we are not able to guess. Please find the some sample text file. I feel it would be good to apply regex.

Thanks, (325 Bytes)

@Boopathi Read text files line by line and iterate while iterating apply regex

Hi @indra.

Now iterating is not an issue my regex is not highlighting if i group together.

Now i want everything to get highlighted in one regex and it is not working for me if i group.


You can adjust it to remove empty entries like this:
str.Split({" "},StringSplitOptions.RemoveEmptyEntries)(0).Trim

also, your Regex patterns look good. Why don’t you just have a different pattern for each value instead of grouping them?

In UiPath, you would just do this:
address = Regex.Match(str, addressPattern).Value
phone = Regex.Match(str, phonePattern).Value
hours = Regex.Matches(str, hoursPattern).ToArray
sunday = hours(0)
and so on

I might be wrong on the Matches cause I was going off the top of my head.

You can also use the activities for Match and Matches, but my examples could be used in an Assign.


@Boopathi Use or condition in regex Refer This

1 Like

Hi @ClaytonM Thank you very much. I applied regex using separate variables and got the required output.

Hi @indra Thanks a lot for your guidance. I got the required output and also implemented.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.