Hi, I need a help with Regex.
Example 1 : From Hyderabad to Mumbai
Example 2 : Travelling from Hyderabad to Mumbai
Example 3 : I am travelling from Hyderabad to Mumbai.
I need a string after the word ‘From’.
For all the above 3 examples , I need Hyderabad as the output.
Can you please help me with the regex for the above scenarios.
ppr
(Peter Preuss)
September 5, 2023, 9:16am
2
we enabled regex option for case insensitive matching and would later trim the match
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum
myStrValue =
strValue = System.Text.RegularExpressions.Regex.Match(strText,strPattern,RegexOptions.IgnoreCase).Value.Trim()
lrtetala
(Lakshman Reddy)
September 5, 2023, 9:19am
4
Hi @Konda_Sai_Charan_Goud
(?<=From|from).*(?= to)
Parvathy
(PS Parvathy)
September 5, 2023, 9:21am
5
Hi @Konda_Sai_Charan_Goud
Use this expression in Find Matching Patterns activity
(?<=From\s|from\s)[\w]+(?=\sto)
or
strvar="Example 1 : From Hyderabad to Mumbai
Example 2 : Travelling from Hyderabad to Mumbai
Example 3 : I am travelling from Hyderabad to Mumbai."
Matches= System.Text.RegularExpressions.Regex.Match(strvar,"(?<=From\s|from\s)[\w]+(?=\sto)").Value
Hope it helps!!
ppr
(Peter Preuss)
September 5, 2023, 9:45am
6
In addition to above would also give a hint on the risked reliability.
Ungreedy:
we will stop at the first to - but too early
Greedy / Default:
we will stop at the last to - but to late
When the city names can create this type of risks and reliability is needed we would recommend to stabilize / enhance the retrival as well
system
(system)
Closed
September 8, 2023, 10:26am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.