Click here to Skip to main content
15,890,282 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a content which is really complicated.
In the content there is a JSON key that I need its value. Consider the content below:
"THE_KEY": "THE_VALUE_WHICH_DIFFERS_EVERYTIME"


How can I access the value of the key with Regex in Python? Consider the key is always the same but the value changes all over the time. Thanks!

What I have tried:

I have tried ways which are not related to the question and I understood I should use this way.
Posted
Updated 14-Aug-21 5:35am
Comments
Patrice T 13-Aug-21 20:40pm    
What Regex did ou tried ?
Richard MacCutchan 14-Aug-21 4:09am    
Why are you using regex? Python has excellent support for JSON.

1 solution

I would use built in JSON support, it's much more flexible.

But ... if you must use a Regex, you could try:
(?<=\"THE_KEY\"\s*:\s*\").+?(?=\")


If you are going to play with regular expressions, then get a copy of Expresso[^] - it's free, and it examines and generates Regexes.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900