[Solved]Flow.response.content.replace regex?


#1

This doesn’t work, I’m trying to match any letter using /w . What would be the right way to do this?

import mitmproxy
import re

def response(flow):
    old = b'Onlin\w{1}'
    new = b'Offline'
    flow.response.content = flow.response.content.replace(old, new)

#3

Got a solution!

import mitmproxy
'''sudo pip3 install regex'''
import re
def response(flow):
    old = b'Onlin\w'
    new = b'Offline'
    # https://docs.python.org/3/library/re.html#re.sub
    flow.response.content = re.sub(old, new, flow.response.content)