0

I have following

\"url\": \"\\\/maru.php?superalox=1\", \"params\": {\"params\": \"EgtmbUtXdUZWdDF2SSoCCABQAQ%3D%3D\", \"session_value\": \"QUFFLUhqbnQ4eW5HeEZYdDBULU5EVk1LREU2VndMMm1nd3xBQ3Jtc0trMUlMOWRqTWxpS0pOT2pNUVN6RENVU3k0Tmc4blplodexsWkxrVDRmOUN2Q0lXVkl1N0YwUFhoV1puQ3ZFQm10X1RzNWR4Q3RUeG5kMkdLNnNobTUyRkNuaG90d2c=\"}, \"log_params\":

i want to extract the value of params which is EgtmbUtXdUZWdDF2SSoCCABQAQ%3D%3D

i have tried this but it didnt work

my_text = """ \"url\": \"\\\/maru.php?superalox=1\", \"params\": {\"params\": \"EgtmbUtXdUZWdDF2SSoCCABQAQ%3D%3D\", \"session_value\": \"QUFFLUhqbnQ4eW5HeEZYdDBULU5EVk1LREU2VndMMm1nd3xBQ3Jtc0trMUlMOWRqTWxpS0pOT2pNUVN6RENVU3k0Tmc4blplodexsWkxrVDRmOUN2Q0lXVkl1N0YwUFhoV1puQ3ZFQm10X1RzNWR4Q3RUeG5kMkdLNnNobTUyRkNuaG90d2c=\"}, \"log_params\": """

extract_data = re.search(r'(\\\"params\": \\\")(\w*)', my_text)
print(extract_data)

Thanks

2 Answers 2

1

You can use:

re.search(r'"params": "([^"]+)"', my_text).group(1)
Sign up to request clarification or add additional context in comments.

Comments

0

I've been using the following with great success:

(["'])(?:(?=(\\?))\2.)*?\1

It supports nested quotes as well.

This also works: (["'])(\?.)*?\1 Easier to read.

For those who want a deeper explanation of how this works, here's an explanation from user ephemient:

([""']) match a quote; ((?=(\\?))\2.) if backslash exists, gobble it, and whether or not that happens, match a character; *? match many times (non-greedily, as to not eat the closing quote); \1 match the same quote that was use for opening.

This is copied from another answer found here: RegEx: Grabbing values between quotation marks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.