# Find and replace regex with capturing group

**URL:** <https://community.postman.com/t/find-and-replace-regex-with-capturing-group/20558>\
**Category:** Help Hub\
**Tags:** search\
**Created:** [February 18, 2021, 9:19pm UTC](https://community.postman.com/t/find-and-replace-regex-with-capturing-group/20558 "2021-02-18T21:19:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfbriere](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jfbriere/32/8444_2.png) [@jfbriere](https://community.postman.com/u/jfbriere)\
**Post date:** [February 18, 2021, 9:19pm UTC](https://community.postman.com/t/find-and-replace-regex-with-capturing-group/20558/1 "2021-02-18T21:19:35Z")

</div>

In Postman, the find utility allows to use a regex to search through collections, environments, etc.  
Is it possible to use capturing groups to do the replace?

---

<div class="post-metadata">

**Author:** ![JessePelton](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@JessePelton](https://community.postman.com/u/JessePelton)\
**Post date:** [March 15, 2021, 12:58pm UTC](https://community.postman.com/t/find-and-replace-regex-with-capturing-group/20558/2 "2021-03-15T12:58:02Z")

</div>

Not that I’ve been able to find. I know of two common conventions for referring to capture group 1 in replacements: **$1** and **\1**. Neither works for me.

Postman’s find and replace regex support is quirky, and as far as I can tell, undocumented. One other oddity is that the **^** beginning of line anchor doesn’t work if followed by white space (**^[\t]**, **^\s** , or **^** followed by a space character).

---

<div class="post-metadata">

**Author:** ![aodennison](https://avatars.discourse-cdn.com/v4/letter/a/71e660/32.png) [@aodennison](https://community.postman.com/u/aodennison)\
**Post date:** [January 20, 2023, 9:26pm UTC](https://community.postman.com/t/find-and-replace-regex-with-capturing-group/20558/3 "2023-01-20T21:26:30Z")

</div>

I just tried in the request/text editor: Find and replace (^h) with a regex to cleanup trailing whitespace:  
Find: (._?)\s+$  
Replace: $1  
which worked as expected.  
Since I consider regex’s to be write once, read never:  
(._?) – says capture stuff non-greedy. otherwise this matches whitespace too  
\s+$ – says match 1 or more whitespace at end of line.

$1 replace the entire match with the group.

When I try to search collections using the above regex, it does not find all of the correct matches.

A poor alternative is to export a collection and edit the JSON directly, then reimport. I use a unique name for the collection to avoid overwriting precious code after a bulk-edit. I know this does not completely answer the post, but it may do in a pinch.

---

<div class="post-metadata">

**Author:** ![docking-module-phys9](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@docking-module-phys9](https://community.postman.com/u/docking-module-phys9)\
**Post date:** [April 27, 2023, 11:26pm UTC](https://community.postman.com/t/find-and-replace-regex-with-capturing-group/20558/4 "2023-04-27T23:26:05Z")

</div>

I just now tried using `$1` in the “REPLACE WITH” field and Postman replaces the text with a literal dollar-sign and numeral one.

I agree with @aodennison - it would be nice to not have to export, fix, re-import but I’m not sure what else to do.

Like @JessePelton , I’ve tried **$1** , **\1** , **/1** , **$1** , and on and on.

And I get nothing when searching in this site or in a search-engine. Do Postman employees check this site much, I wonder (I hope!)?

Postman for Desktop on a Mac:  
Version 10.8.8  
UI Version: 10.8.8-ui-230201-0452  
Desktop Platform Version: 10.8.0 (10.8.0)
