Regex or String manipulation needed in order to insert a new line before a value

Hi! I have a big string lets say something like:
1 01/02/2022 AAAAA BBBBBBBBBBB / 0.00 0.00 0.00 15.24 0.76 0.00 0.00 0.00 0.00 16.00
0.00 16.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Coca Cola 5 15.24 0.76 16.00
2 01/02/2022 AAAAA BBBBBBBBB / 0.00 0.00 0.00 15.24 0.76 0.00 0.00 0.00 0.00 16.00
0.00 16.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Apa plata 5 15.24 0.76 16.00
3 02/02/2022 AAAAAA BBBBBBBBBBB / CCCCCCCCCC 0.00 0.00 0.00 9.52 0.48 0.00 0.00 0.00 0.00 10.00
10.00 0.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Biscuiti 5 9.52 0.48 10.00
4 02/02/2022 AAAAA BBBBBBBBB / 0.00 273.95 52.05 0.00 0.00 0.00 0.00 0.00 0.00 326.00
326.00 0.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Restaurant Automat (19%) 19 273.95 52.05 326.00
5 03/02/2022 AAAAA BBBBBBBB / 0.00 0.00 0.00 7.62 0.38 0.00 0.00 0.00 0.00 8.00
8.00 0.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Apa plata 5 7.62 0.38 8.00

And I need to add a new row / new line BEFORE each digit and date (including the first row) it should look like this:

1 01/02/2022 AAAAA BBBBBBBBBBB / 0.00 0.00 0.00 15.24 0.76 0.00 0.00 0.00 0.00 16.00
0.00 16.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Coca Cola 5 15.24 0.76 16.00

2 01/02/2022 AAAAA BBBBBBBBB / 0.00 0.00 0.00 15.24 0.76 0.00 0.00 0.00 0.00 16.00
0.00 16.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Apa plata 5 15.24 0.76 16.00

3 02/02/2022 AAAAAA BBBBBBBBBBB / CCCCCCCCCC 0.00 0.00 0.00 9.52 0.48 0.00 0.00 0.00 0.00 10.00
10.00 0.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Biscuiti 5 9.52 0.48 10.00

4 02/02/2022 AAAAA BBBBBBBBB / 0.00 273.95 52.05 0.00 0.00 0.00 0.00 0.00 0.00 326.00
326.00 0.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Restaurant Automat (19%) 19 273.95 52.05 326.00

5 03/02/2022 AAAAA BBBBBBBB / 0.00 0.00 0.00 7.62 0.38 0.00 0.00 0.00 0.00 8.00
8.00 0.00 0.00 0.00 0.00
SERVICIU COTA TVA NET TVA BRUT
Apa plata 5 7.62 0.38 8.00

Any ideas?

You’re adding a VbCrLf after every 4th line. So just split the entire text on VbCrLf into an array. Then For Each through the array and concatenate into a string variable. Every 4th iteration of the loop, add VbCrLf to the end.


(\d+ [\d\/]{10})

2 Likes

I can’t add that after every 4th line because some data from the string has more than than 4 lines

Oh, that wasn’t obvious from your example data. Sorry about that.

Yeah sorry I just copied the first 5 things from the string but it has over 200 xD.
I’ll try @ppr 's method

1 Like

in case of the code line is needed:

strNew = Regex.Replace(strString,strPattern, Function (m) Environment.NewLine & m.Groups(1).Value)

taken from:

1 Like

Needed indeed thank you!

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