Getting text from string between two characters

Hi,

How can i get text between “[” and “]” brackets from textfile. And these brackets should also be in result like this:

“Some text [ between brackets ] is all we want” to this:

“[ between brackets ]”

Trying to parse json array so i can get it to DataTable. Json includes at beginning some json object content so UiPath jsondeserialise activity can’t fetch array from json…

-mikko

Hi.

A regex pattern would work. If you want to include the brackets, then the pattern would be like:

"\[(.*)\]"
System.Text.RegularExpressions.Regex.Match(text, pattern).Value

Additionally, if you want to parse that to an array, then maybe you can use that value in something like this:

JArray.Parse(extractedtext).Select(Function(x) If(x.ToString.Contains(" "),x.ToString.Trim,x)).ToArray //where extractedtext is what you pulled using the Regex

—just throwing a few ideas out there

Hope it helps.

Regards.

2 Likes

Thanks @ClaytonM for reply

Added regex but now it return empty string. Might reason be that json string is at many rows?

Main.xaml (10.4 KB)

Hi.

Adjust the pattern to check for \n or \r

I tested the pattern successfully with this:

System.Text.RegularExpressions.Regex.Match(ResponseString, "\[((.|\n|\r)*)\]").Value

Regards

1 Like

@ClaytonM Thanks, it works now!

-mikko