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?
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).
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.
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)