Boopathi
(Boopathi Manogar)
August 22, 2019, 1:12pm
1
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
Thanks,
Ula
Boopathi
(Boopathi Manogar)
August 22, 2019, 2:37pm
2
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 -
For address - (.+?USA)
I don’t know how to group them together all the required values. Could anyone help me now?
Thanks,
Ula
Hi.
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.
Regards.
indra
(Indra)
August 22, 2019, 3:06pm
4
@Boopathi Can you confirm every time format will be same or different
Boopathi
(Boopathi Manogar)
August 22, 2019, 3:07pm
5
Hi @indra yes time format remains same.
Thanks
Boopathi
(Boopathi Manogar)
August 22, 2019, 3:12pm
6
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,
UlaOperatinghours.zip (325 Bytes)
indra
(Indra)
August 22, 2019, 3:17pm
7
@Boopathi Read text files line by line and iterate while iterating apply regex
Boopathi
(Boopathi Manogar)
August 22, 2019, 3:24pm
8
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.
Thanks,
Ula
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.
Regards.
indra
(Indra)
August 22, 2019, 3:37pm
10
@Boopathi Use or condition in regex Refer This
1 Like
Boopathi
(Boopathi Manogar)
August 23, 2019, 1:25pm
11
Hi @ClaytonM Thank you very much. I applied regex using separate variables and got the required output.
Boopathi
(Boopathi Manogar)
August 23, 2019, 1:25pm
12
Hi @indra Thanks a lot for your guidance. I got the required output and also implemented.
system
(system)
Closed
August 26, 2019, 1:25pm
13
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.