# Regex replace certain string pattern with newline vblf

**URL:** <https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322>\
**Category:** Help\
**Tags:** find-references, replace, question, studio, activities, regex, system\
**Created:** [October 24, 2023, 7:43am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322 "2023-10-24T07:43:14Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![llayla](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/llayla/32/263533_2.png) [@llayla](https://forum.uipath.com/u/llayla)\
**Post date:** [October 24, 2023, 7:43am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/1 "2023-10-24T07:43:14Z")

</div>

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)

 ![Screenshot_1](https://global.discourse-cdn.com/uipath/original/4X/f/2/d/f2d59735bcf1df300d4d2257e073ec61d405db1b.png)

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

---

<div class="post-metadata">

**Author:** ![lukas.gamper](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lukas.gamper/32/181327_2.png) [@lukas.gamper](https://forum.uipath.com/u/lukas.gamper)\
**Post date:** [October 24, 2023, 8:22am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/2 "2023-10-24T08:22:09Z")

</div>

I think you could do it like:

 ![image](https://global.discourse-cdn.com/uipath/original/4X/6/e/d/6ed84b38b51fffe3d600bc82bf6ec5ba398896a4.jpeg)

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 🙂

---

<div class="post-metadata">

**Author:** ![llayla](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/llayla/32/263533_2.png) [@llayla](https://forum.uipath.com/u/llayla)\
**Post date:** [October 24, 2023, 8:29am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/3 "2023-10-24T08:29:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![lukas.gamper](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lukas.gamper/32/181327_2.png) [@lukas.gamper](https://forum.uipath.com/u/lukas.gamper)\
**Post date:** [October 24, 2023, 8:33am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/4 "2023-10-24T08:33:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![llayla](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/llayla/32/263533_2.png) [@llayla](https://forum.uipath.com/u/llayla)\
**Post date:** [October 24, 2023, 8:52am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/5 "2023-10-24T08:52:49Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![lukas.gamper](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/lukas.gamper/32/181327_2.png) [@lukas.gamper](https://forum.uipath.com/u/lukas.gamper)\
**Post date:** [October 24, 2023, 9:06am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/6 "2023-10-24T09:06:07Z")

</div>

“\:[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

---

<div class="post-metadata">

**Author:** ![llayla](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/llayla/32/263533_2.png) [@llayla](https://forum.uipath.com/u/llayla)\
**Post date:** [October 24, 2023, 9:16am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/7 "2023-10-24T09:16:41Z")

</div>

thank you for the help

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [October 27, 2023, 9:17am UTC](https://forum.uipath.com/t/regex-replace-certain-string-pattern-with-newline-vblf/658322/8 "2023-10-27T09:17:07Z")

</div>

Closed on October 27, 2023, 9:17am UTC

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