How to split string using regex

Hello all,
Can anyone know how to split the string using regex where whitespace as a delimiter?

Input string:
xxx 0190 a b c

Expected output:
xxx
0190
a b c

Hi,

Can you share if there is a rule not to split “a b c” part to a, b and c?

Regards,

No @Yoichi . There is no rule. Main issue is I need to split string based on whitespace using regular expression.

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Split(yourString,"\s+")

Regards,

then above mention is not conform with expected output:

…
…
a b c

as here the space for splitting was not applied.

We agree with:

Hi @Lalitha_Selvaraj

Assign -> Input = "xxx 0190 a b c"

Assign -> Output = System.Text.RegularExpressions.Regex.Matches(Input.ToString, "[A-Za-z0-9]+")

Message Box -> String.Join(Environment.NewLine, Output.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Input is of DataType System.String. Output is of DataType System.Collections.Generic.IEnumerable(System.Text.RegularExpressions.Match)

Regards

I have added a b c its because some times the string looks like “firstname middlename last name” . so i have to capture all the strings(firstname, middlename, last name)

Hi,

Input:-
image

Output:-
image

Xaml file:-
Main.xaml (8.1 KB)

If this works for you, please mark it as a solution, so others can refer the same. :slight_smile:
Thanks

so it is not a consequent split on space.

In such cases we would check more on reliable patterns and can use techniques of inserting delimiters like:

so we can split on | afterwards and would also trim the splits

Hi @ppr . Thanks. Can you explain more in detail. if possible, can you post the code for reference.

Have a look at this series:
grafik

done within:
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum

And feel free to break it down in smaller sub parts

1 Like

Thanks @ppr . Its working.

Perfect, so the topic can be closed
Forum FAQ - How to mark a post as a solution - News / Tutorials - UiPath Community Forum

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