# Find and Replace functionality with new line inserted does not work

**URL:** <https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327>\
**Category:** Help Hub\
**Tags:** collections\
**Created:** [March 12, 2021, 9:55pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327 "2021-03-12T21:55:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![amursa](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@amursa](https://community.postman.com/u/amursa)\
**Post date:** [March 12, 2021, 9:55pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/1 "2021-03-12T21:55:15Z")

</div>

**amursa**  
I need to substitute part of the body request with 2 json key-values pairs. I figured out the find regexp using [https://regex101.com/](https://regex101.com/) and it works, but I can’t find how do I add new line in substitution string. Could you pls suggest?  
for example [\r\n\t\v]+”key1″: “value1”,[\r\n\t\v]+. to be replaced with “key1”: “value1”,\n “key2”: “value2”,\n.  
It does not interpret \n and uses it as a string, unfortunately.

So, I need a two line substitution, like:  
“key1”: “value1”,  
“key2”: “value2”

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [March 12, 2021, 11:13pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/2 "2021-03-12T23:13:45Z")

</div>

Heu Amursa,

so this is mostly a JS question since Postman doesn’t have an area to do regex directly.  
Can you provide the script example in which you use this in?

---

<div class="post-metadata">

**Author:** ![amursa](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@amursa](https://community.postman.com/u/amursa)\
**Post date:** [March 13, 2021, 12:50pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/3 "2021-03-13T12:50:15Z")

</div>

I have part of my json looking like this:  
“key1”:[“value 1”, “value 2”],

I find it with this regexpt THAT WORKS JUST LIKE I NEED:  
^“key1”:\s?[“value\s?[0-9]+”\s?,\s?“value\s?[0-9]+[”]],\n+?  
“key1”:[“value 1”, “value 2”], \n “key2”: ["test1],

In the find replace POSTMAN tab I provide in replace following string:  
“key1”:[“value 1”, “value 2”], \n “key2”: ["test1],  
Substitution does not interpret \n and results is in one line:  
“key1”:[“value 1”, “value 2”], \n “key2”: ["test1],

---

<div class="post-metadata">

**Author:** ![postman-kyle](https://avatars.discourse-cdn.com/v4/letter/p/47e85d/32.png) [@postman-kyle](https://community.postman.com/u/postman-kyle)\
**Post date:** [March 16, 2021, 8:35pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/4 "2021-03-16T20:35:33Z")

</div>

so you are trying this in the find and replace tab, ok thank you.

Trying your examples in Regex101 seem to select but you should be testing using Javascript.

so for example:

```
const regext = /[\r\n\t\v]+"key1": "value1",[\r\n\t\v]+/gm;
regext.test(v)

```

where v is your string. Following your example I’m getting false.  
I wonder if you have to escape your \n ?

---

<div class="post-metadata">

**Author:** ![amursa](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@amursa](https://community.postman.com/u/amursa)\
**Post date:** [March 16, 2021, 9:08pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/5 "2021-03-16T21:08:44Z")

</div>

Hi Kyle, I’m able to find my string with no problem. Substitution is the issue. How do you tell postman to insert new line cause \n is not working.

---

<div class="post-metadata">

**Author:** ![MadeWithPryde](https://avatars.discourse-cdn.com/v4/letter/m/9d8465/32.png) [@MadeWithPryde](https://community.postman.com/u/MadeWithPryde)\
**Post date:** [September 27, 2022, 3:03pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/6 "2022-09-27T15:03:57Z")

</div>

@amursa, were you ever able to find a solution to this problem?

I also just ran into this, is their a current bug report on this?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 2:46pm UTC](https://community.postman.com/t/find-and-replace-functionality-with-new-line-inserted-does-not-work/21327/7 "2024-12-12T14:46:55Z")

</div>

Closed on December 12, 2024, 2:46pm UTC

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