Tricky Regex

Given this data in one string variable…

First Name FNAME Text Paul
City CITYNAME Text Miami
Price PRC Amount 5.00
Start Date STDT Date 5/25/2022

Say I supply the strings “Price” and “Amount”, I want to get the value “5.00” or if I supply “City” and “Text” I get back “Miami”

In other words, knowing the field name and type, I want the value on the same line after the type.

The middle value (ie FNAME, CITYNAME) is the internal database field name and I won’t know that so can’t use it in the Regex expression.

I’d be fine with splitting it on VbCrLf and then looping through the rows until I find the row I want and then only Regex parsing that row, if it’s easier to do “find the text after ‘First Name * Text’”

Does this work for you?

@postwick You can try the below one. Attached workflow for ref

Variable of type string Output = System.Text.RegularExpressions.Regex.Match(StrText,"(?<="+StrData1+".*"+ StrData2+").*").ToString
  • StrText is the input string
  • StrData1 variable should contain field name
  • StrData2 variable should contain field type

Example.zip (2.6 KB)

1 Like

No. If it did I wouldn’t be asking. I only have a basic understanding of Regex.

That gives me this:

image

@postwick Try the below one

@postwick It would help!!

Oh, but it works in UiPath. That’s odd.

Regex101.com does support .NET C# flavor also nowadays.

1 Like

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