# How to exclude string in response body

**URL:** <https://community.postman.com/t/how-to-exclude-string-in-response-body/5655>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 29, 2019, 12:36pm UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655 "2019-05-29T12:36:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Calibraticboy](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Calibraticboy](https://community.postman.com/u/Calibraticboy)\
**Post date:** [May 29, 2019, 12:36pm UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/1 "2019-05-29T12:36:32Z")

</div>

Hi,

I am struggling with some issue regarding data in response body.  
In my response body i get “body”: “Please go to [https://admin.dev.foo.com](https://admin.dev.foo.com) to reset your password”.  
I then create a set environmnet variable to transer “Please go to [https://admin.dev.foo.com](https://admin.dev.foo.com) to reset your password”. The issue is that I want to exclude “Please go to” and “to reset your password” and only include the url -"[https://admin.dev.foo.com](https://admin.dev.foo.com) ".  
Is there a solution to exculde some strings/text ?

 ![env](https://us1.discourse-cdn.com/getpostman/original/3X/3/e/3e128439c3ca3f8e68f621e716da375746641af0.png)

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [May 29, 2019, 12:51pm UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/2 "2019-05-29T12:51:18Z")

</div>

Hey @Calibraticboy,

You could use Regex and try something like this:

```
let jsonData = pm.response.json().message.body

var url = jsonData.match(/(https?:\/\/[^]*)/)[1];
    
pm.globals.set('url', url) 

```

I’ve only tested this out locally with the string _“Please go to [https://admin.dev.foo.com](https://admin.dev.foo.com/) to reset your password”_ and it seemed to extract and save the URL.

I’m absolutely not a regex expert 🙂

---

<div class="post-metadata">

**Author:** ![Calibraticboy](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Calibraticboy](https://community.postman.com/u/Calibraticboy)\
**Post date:** [May 31, 2019, 9:18am UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/3 "2019-05-31T09:18:44Z")

</div>

Thanks for your help 🙂I will give it a try.

---

<div class="post-metadata">

**Author:** ![postman-paul540](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/postman-paul540/32/149_2.png) [@postman-paul540](https://community.postman.com/u/postman-paul540)\
**Post date:** [May 31, 2019, 2:45pm UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/4 "2019-05-31T14:45:22Z")

</div>

Like Danny, I’m absolutely not a regex expert - But here’s how I’d personally tackle your problem:

Let’s say the below response body is returned:

```auto
{
    "subject": "Please go to https://gear4music.com to reset your password"
};

```

My tests tab would have the below to capture that string, and “replace” all the unwanted text with empty values.

![image](https://us1.discourse-cdn.com/getpostman/original/3X/b/8/b8043dba389340dc32c47438ab91e6819fdbabc1.png)

So you’re environment variable will be:

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/d/d70dbd8bffb4f39656bbf3b68be6eddc7f026e10.png)

This is the cool thing about writing code/tests - the same problem can have multiple “solutions” depending on the user’s preference 🙂

---

<div class="post-metadata">

**Author:** ![Calibraticboy](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Calibraticboy](https://community.postman.com/u/Calibraticboy)\
**Post date:** [June 3, 2019, 6:21am UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/5 "2019-06-03T06:21:35Z")

</div>

Looks interesting 🙂  
I will give it a try. Thanks for helping.

---

<div class="post-metadata">

**Author:** ![Calibraticboy](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Calibraticboy](https://community.postman.com/u/Calibraticboy)\
**Post date:** [June 4, 2019, 7:45am UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/6 "2019-06-04T07:45:22Z")

</div>

Works like a charm 🙂

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [June 4, 2019, 8:36am UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/7 "2019-06-04T08:36:10Z")

</div>

Awesome! 🏆

Which method did you go for in the end?

---

<div class="post-metadata">

**Author:** ![Calibraticboy](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@Calibraticboy](https://community.postman.com/u/Calibraticboy)\
**Post date:** [June 4, 2019, 9:02am UTC](https://community.postman.com/t/how-to-exclude-string-in-response-body/5655/9 "2019-06-04T09:02:41Z")

</div>

Both method worked, but I ended working with pfarell solution becuase I am not familiar wirh regex.
