Regex- Strings

Hi, I need to get the value “Termlife”: “30yr LT” and here is my input text. How to get value either in substring/regex?
1, Product:
El Term Life: El 10Yr LT El 15Yr LT E 20Yr LT El 25Yr LT El 30Yr LT
111 Whole Life: 0 SL E L10 111 L15 0 L20 0 L@65 E SPL
El Other:

Hi @Lalitha_Selvaraj

Try this

(\d+Yr LT)

System.Text.RegularExpressions.Regex.Matches(Input.ToString(),"(\d+Yr LT)").Last.Value

Regards,

Hi @Lalitha_Selvaraj

  • str_InputText is your Input Text

To get all the values:

System.Text.RegularExpressions.Regex.Matches(str_InputText,"\d+Yr LT")

To get the Last Value:

System.Text.RegularExpressions.Regex.Matches(str_InputText,"\d+Yr LT").Last

Hope it’ll helps you :slight_smile:
Cheers !!

Hi, I’m getting the below error.

@Lalitha_Selvaraj,

Use Matches you used Match

System.Text.RegularExpressions.Regex.Matches(str_InputText,"\d+Yr LT").Last

Thanks,
Ashok :slight_smile:


@Lalitha_Selvaraj,

Sorry! my bad, Use this one.

System.Text.RegularExpressions.Regex.Matches(str_InputText,"\d+Yr LT").AsEnumerable().Last().Value

Thanks,
Ashok :slight_smile:


Hi @ashokkarale . Still getting the error.

@Lalitha_Selvaraj,

Try typing the LINQ.

Output:
image

Have this sample workflow which is running on my machine.
Sample.xaml (8.5 KB)

Thanks,
Ashok :slight_smile:

@Lalitha_Selvaraj

Try this:


Product = System.Text.RegularExpressions.Regex.Matches(str_InputText,"\d+Yr LT").Last.Value



Note: Make sure System.Text.RegularExpressions is imported.


image


Happy Automation :uipath: