Creating a Python Regex to match a string
I am having a hard time creating a regex for this string. I need to:
- extract the words after Property, until &
- extract the words after Category, until &
- Create a regex to match everything from “cat” until the , before “modifiedBy”
"cat":"Property : TikTok Videos & Category : Insta Videos & User Impact: TBD & User Minutes :
18","modifiedBy"
My current regex is:
"cat":"Property : (?P<property>\w+.*?) & Category : (?P<category>\w+)?
-
This is able to name “property” correctly as “TikTok Videos”.
-
But the named “Category” regex comes up as just the word “Insta”.
If I add a + as in (?P\w+, then it ends up consuming all the way until the end of the string. -
As far as consuming the entire string from “cat” until the last comma before the “modified”, I don’t know how to capture that.
So the end product would be:
- property = TIkTok Videos
- Category = Insta Videos
- Entire_string = “cat”:”Property : TikTok Videos & Category : Insta Videos & User Impact: TBD & User Minutes : 18″
Read more here: Source link