Forced use of regex

In a technical interview, the interviewer gave me 2 lists with data, in one list there were words and in the other sequences of numbers, for example:

List 1
“Hola Mundo”
“Chanchito feliz muy feliz”
“Chanchito feliz 123”

List 2

123 456
12345 12345 123
123 1 123 112

The proof is that for all data I had to remove only whitespace with regex.

I used the method, text.replace(" “,”").tostring
Which worked pretty well, served the purpose.

But the interviewer asked me to forcefully do it with regex.

How can I solve this type of cases SPECIFICALLY with REGEX

thanks for you help

Hi @alexis.mendoza

Try this

\s+

\w+

image

Regards,

@alexis.mendoza
Use one assign activity

FinalString=System.Text.RegularExpressions.Regex.Replace(yourString, "\s", "")

If I use that expression it only returns the first word.
I require med to return everything except spaces, sin utilizar el metodo .recplace

image

image

I can’t use .Replace Method.

Hello

Try this:
Left Assign:
str_Result

Right Assign:
System.Text.RegularExpressions.Regex.Replace(yourString, " ", “”)

\s+ includes all whitespace characters BUT " " is the same as mentioned in your post (text.replace(" “,”").tostring).

Using Regex was the criteria and this is the Regex.Replace method.

Cheers

Steve

Hi,

System.Test.RegularExpression.Regex.Replace method is different with String.Replace method.
However, if you don’t want to use any “Replace” method, the following will work.

String.Join("",System.Text.RegularExpressions.Regex.Matches(yourString,"\S+").Cast(Of System.Text.RegularExpressions.Match).Select(Function(m) m.Value))

Regards,

Hey @alexis.mendoza ,
If you dont want to use Replace then you can use concat and split methods with regex

Below is the input Snapshot
image

Below is the Output Snapshot:

Below is the code:

String.Concat(System.Text.RegularExpressions.Regex.Split(inputText, “\s+”))

And below is the file for your reference

Regex.zip (2.5 KB)

Hope It helps you!

Happy Automation with UiPath :smile:

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