Extract word between two known words

Hi
Is there any way to read a particular word which is between two known words with the help of regex?
eg If input is Name ABCD Age, I need to extract ABCD.

Instead of using substring function, is there any way we can utilize any regex?

Hi,

try this (?<=Name\s).*(?=\sAge)
This is a Lookbehind(Name) and Lookahead(Age)

BR,
Topi

1 Like

Hii
Thanks for quick reply.
I’m sorry as I’m new to regex but where exactly would I use this expression in UiPath?
I mean if I have a variable which holds the string and another one which holds the substring, how will i assign the result of this regex to the substring variable?

(?<=" + labelBefore + “)(.*?)(?=” + labelAfter + ")

Extract Text Between Labels.xaml (7.1 KB)

Regards…!!
Aksh

4 Likes

Thanks a ton. This works!!

Hello Aksh, do you have a Regex Tester reference ?

Hey @marcus

There are many sites exists but i prefers mostly https://regex101.com/ you can also give it a try :slight_smile:

Regards…!!
Aksh

What if we have 1234 instead of ABCD in between ??
or rather 12200.00?

@Robo

did not get u. even the number you are looking then it will be inside a string so it will work with that and then if needed can convert this to int.

*Correct me if I m getting it wrong.

Regards…!!
Aksh

Hi
Is there any way to read a particular word which is between two known words with the help of subscript()?
eg If input is Name1Name ABCD Age,
I need to extract ABCD.
Note-Using Subscript only

Try something like this in Invoke Code activity,

Dim St As String = “string pulled from the textfile suing reader which has key : text I want to keep - end of my string”
Dim pFrom As Integer = St.IndexOf("key : ") + "key : “.Length
Dim pTo As Integer = St.LastIndexOf(” - ")
Dim result As String = St.Substring(pFrom, pTo - pFrom)

Note: “key :” and " -" are the two string of the string’s starting and end which we need to search and get.
we can return the result to the workflow and can use it

Hi
Is there any way to read a particular word which is between two known words with the help of subscript()?
eg If input is Name1Name ABCD Age,
I need to extract ABCD.
Note-Using Subscript only

Guys,

Just a question, How did you manage to associate to put the variable type “System.Collections.Generi.IEnumerable<System.Tex.RegularExpressions.Match>” on the variable “matchValue”?

I tried to find on the main directory but I cant find the same one. Is there something that I should do on the variable itself for it to work.

1 Like

Hi Aksh,

I’m not able to extract words as intended, can you look at below content and xaml file as to where is the problem?

rfp-scope-ui.xaml (6.8 KB)
LWSystems-UI.pdf (59.5 KB)