Need Regex Expression

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.

we enabled regex option for case insensitive matching and would later trim the match

grafik

[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

myStrValue =

strValue =  System.Text.RegularExpressions.Regex.Match(strText,strPattern,RegexOptions.IgnoreCase).Value.Trim()

Cheers @Konda_Sai_Charan_Goud

Hi @Konda_Sai_Charan_Goud

(?<=From|from).*(?= to)

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!!

In addition to above would also give a hint on the risked reliability.

Ungreedy:
grafik
we will stop at the first to - but too early

Greedy / Default:
grafik
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

e.g. by:

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