Regex replace certain string pattern with newline vblf

So, i have a text file. The purpose is to Add VBCRLF (newline) in certain part of string . Here the example of the string:

Before (The string don’t have any newline caharcter):
{1:F01ABCDIDJAXXXX0001212544}{2:O9001038231020QWERIDJRAXXX00011102422310201038N}{3:{113:0070}}{4::20:94493831555385/900:21:0799102034308001:25:520008000990:32A:231020USD0,:72:/ESETDATE/2310201038+0000/OID/231020ABCDDJAXXXX0001019040/AMNT/10000000000001,12-}

Expected condition:
if we see on notepad ++ will look like this (make sure you’re enable the symbols)

Below i’ve try to write the logic:
1.Find character {4: in whole string, then replace with {4:+vbLf
2. using replace regex

For each character with pattern
^:[\d\w]+:
(like :20: )
Then replace with vbLf+originalcharacter

  1. using replace regex

For each character with pattern
/(.*?)/
(like /AMNT/ )
Then replace with vbLf+originalcharacter

If anyone can help to solve this, appreciate it. Thanks

I think you could do it like:

You would need to use 3 “Find Matching Patterns”, to get 3 collections strings you want to replace.

In the “For Each” you could have 1 Multiple assign to replace the text with: “Text.Replace(currentItem.ToString,currentItem.ToString + " \n”)" where “\n” could also be “vbLf”.

If your patterns work, you can use them, else you could do:
\{[0-9]{1,2}\: ← Depending if your Patterns can have 2 numbers, else you can drop {1,2}

\:[0-9]{2}\: ← to find patterns like “:nn:”

\/[A-Z]*\/ ← to find patterns like /TEXT/ (My understanding was only uppercase characters?

Hope that helps.

Kind Regards

Edit: added extra \ because they wouldnt show otherwise :slight_smile:

thanks for the help, i am trying to implement it now, hope will works

I wrote something wrong, you would need to join your 3 collections or do 3 for loops, else you will only replace matches of 1 collection.

Sorry

@lukas.gamper it works. but the RegEx still need modification :smile:

so for this one:

:[0-9]{2}: ← to find patterns like “:nn:”

i want to change it to be find any character inside “:”, for example “:20:”, “:32a”

and for this one:

/[A-Z]*/ ← to find patterns like /TEXT/ (My understanding was only uppercase characters?

i want to change it to be find any character whether upper/lowercase inside “/”, for example "/OID/, “/abcd/”

Thank you

“\:[0-9a-zA-Z]*[^-s]\:” for “:nnabbABC:”
“\/[a-zA-Z]*\/” for /TEXTtext/

hope that helps.
Kind Regards

Edit: added \ before * in first expression so it would show

thank you for the help

1 Like

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