paultech5
(Paul T.C.)
February 2, 2024, 1:04pm
1
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!
1 Like
ppr
(Peter Preuss)
February 2, 2024, 2:19pm
3
Are you looking for:
String.Join(";", YourMatchesVar.Cast(Of Match).Select(Function (m).Value.Trim()))
This CheatSheet introduces the basic use of regex functions. With further examples also special cases are presented.
Introduction
From the namespace System.Text.RegularExpressions following methods are offered:
Regex.Match
Regex.Matches
Regex.isMatch
Regex.Replace
Regex.Split
A simple usage for example would look like this:
[grafik]
Recommendation:
add System.Text.RegularExpressions to the imports:
[grafik]
it allows to use the shortened statement, as the namespace part can be ommited…
1 Like
paultech5
(Paul T.C.)
February 2, 2024, 2:54pm
4
This is not helpful as i am not able to convert the matched values to a string.
ppr
(Peter Preuss)
February 2, 2024, 3:02pm
5
paultech5:
This is not helpful
then it would be helpfully to tell us more clear on what is the input / output
we have understood:
all = is matches
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
Parvathy
(PS Parvathy)
February 2, 2024, 3:42pm
6
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
paultech5
(Paul T.C.)
February 2, 2024, 4:31pm
7
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)
paultech5
(Paul T.C.)
February 2, 2024, 4:36pm
8
I have shared my file along with the info.
Parvathy
(PS Parvathy)
February 2, 2024, 4:36pm
9
@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.
Output :
paultech5
(Paul T.C.)
February 2, 2024, 4:47pm
11
Yes, that I could manage also.
This is the output example.
I want the matches to go after “WorkshopItems=”
ppr
(Peter Preuss)
February 2, 2024, 5:01pm
12
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
paultech5
(Paul T.C.)
February 2, 2024, 5:21pm
13
I do not understand.
Where and how should I use the string join?
Parvathy
(PS Parvathy)
February 2, 2024, 5:22pm
14
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!!
ppr
(Peter Preuss)
February 2, 2024, 5:32pm
15
mark your output file like:
WorkshopItems=#WSItems#
Mods=#MDItems#
Read in the file as you had done:
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
ppr
(Peter Preuss)
February 2, 2024, 5:41pm
16
ppr:
strFlattenMOD
Find some starter help here:
Main.xaml (11.4 KB)
UpdateReady_Path.txt (39 Bytes)
1 Like
paultech5
(Paul T.C.)
February 3, 2024, 9:54am
17
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?
Parvathy
(PS Parvathy)
February 3, 2024, 9:58am
18
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
paultech5
(Paul T.C.)
February 3, 2024, 10:04am
19
Seems to work.
Appreciate it.
1 Like