How to write all RegEx currentitems in one row order?

Hello,

I need to insert in order all matches found with RegEx in a text file.
Also I need them all to come only after a specific text and be separated by a “;” no spaces required in between.
I am currently using a for each activity and the correct matches are being extracted, I verified the result with log message.
I think i need the right expression to write everything in one row, as mentioned above.

Can anyone help?
Thanks.

Hi Paultech5,
You can find all the information about Regex in the following Post.

Hope helps you!

Are you looking for:

String.Join(";", YourMatchesVar.Cast(Of Match).Select(Function (m).Value.Trim()))

1 Like

This is not helpful as i am not able to convert the matched values to a string.

then it would be helpfully to tell us more clear on what is the input / output

we have understood:
all = is matches

grafik

in this you want to insert in a text file at a particular position.

So feel free to elaborate more on this, when you feel mistaken

Hi @paultech5

Try the below syntax:

String.Join("; ", matches.Cast(Of Match)().Select(Function(m) m.Value).ToList())

In the meanwhile can you share the input and your expected output so that I can help you out.

Regards

OK, so I will share my project.zip.
this is just an exercise i tried to do so its nothing serious but i would like to understand how do I achieve what I thought of.
You will find the input in the files folder of the project (ModList_Path), as well as the text file in which i am trying to output the result. For starters I have been trying to figure out how to string the list in one row.
I hope it’s enough.

Update Mods.zip (118.0 KB)

I have shared my file along with the info.

@paultech5

I will check let you know

Regards

1 Like

Hi @paultech5 ,

Could you be more specific on the Output Representation you need ? Currently, with a Slight modification of the Expression in the Log Message in your workflow, we get the Workshop ID values.

image

Output :
image

Yes, that I could manage also.
This is the output example.
I want the matches to go after “WorkshopItems=”
image

we had shown, on how to get a flatten string from the matches with string join

A few options:

  • place a place holder within the File like #WSITEM# and replace it with the flatten list
  • Use an anchored REGEX along with replace

here for the substition we would use the flatten string

I do not understand.
Where and how should I use the string join?

Hi @paultech5

The below syntax will print all the Workshop Items

String.Join(", ", RegExModID.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

The below syntax will print Mods

String.Join(", ", RegExModName.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Check the below image for better understanding.

Happy to help if you have any more queries or requirements
Hope it helps!!

mark your output file like:

WorkshopItems=#WSItems#
Mods=#MDItems#

Read in the file as you had done:
grafik

We don’t need the for each

Assign Activity:
strFlattenWSI | String Variable = String.Join(";", RegExModID.Select(Function (m) m.Value.Trim))

Assign Activity:

strFlattenMOD | String Variable = String.Join(";", RegExModName.Select(Function (m) m.Value.Trim))

Assign Acticity:
ServerModsUpdated = ServerModsUpdated.Replace("#WSItems#", strFlattenWSI )

Assign Acticity:
ServerModsUpdated = ServerModsUpdated.Replace("#MDItems#", strFlattenMOD )

And write out ServerModsUpdated / use modified text

Find some starter help here:

Main.xaml (11.4 KB)
UpdateReady_Path.txt (39 Bytes)

Thanks for your help.
In what activity should I use this syntax? Should I use a write text file activity?
Do I still need the ForEach loop to iterate the matches?

Not needed at all @paultech5

You can use the below syntax condiiton directly in Write Text File activity After both FInd Matching Patterns:

"WorkshopItems="+String.Join(", ", RegExModID.Cast(Of Match)().Select(Function(m) m.Value.Trim()))+ Environment.NewLine + "Mods="+String.Join(", ", RegExModName.Cast(Of Match)().Select(Function(m) m.Value.Trim()))

Hope it helps!!

2 Likes

Seems to work.
Appreciate it.

1 Like

Thank you @paultech5

Happy Automation!!