How to change HTTP response body using Charles Proxy rewriting tool and regex?

Am I trying to change the body of an HTTP response using Charles Proxy using the rewrite / regex tool? The answer is JSON.

So, part of the return body of the JSON response:

"unavailablePosts": ["AA", "BB"], 

I want too:

 "unavailablePosts": "XXX", 

I am trying to set up Charles's correspondence as follows:

enter image description here

So the regex looks like this:

 "unavailablePosts": \[(.*)\], 

But ... (as I ask this question) this does not work, i.e. nothing changes in the body of the response.

+5
source share
1 answer

I believe there are some line breaks between the values, and to match them you need to add \s* (zero or more spaces) around : and use [\s\S]*? (any characters are 0+, but as small as possible since *? is a lazy quantifier) ​​to match a substring between [ and ], ,:

  "unavailablePosts"\s*:\s*\[([\s\S]*?)\], 
+3
source

Source: https://habr.com/ru/post/1259267/


All Articles