I'm writing a regex with Python, and I'm facing this problem.
My regex is the following :
:(\s )"[^:"]*?([^"]:)?[^:"]*?"[^:"]*?([^"]:)?[^:"]*?"([,}]\s*)
My goal is to capture text like this :
: "Some : text " and : another",
: "Some " text",
: "Some text : and, repeating : one " and : another",
The above regex works well with the first two texts.
But now, I'm trying to capture the third text with regex like this but it doesn't work at all.
:(\s )"([^:"]*?([^"]:)?[^:"]*?)*"([^:"]*?([^"]:)?[^:"]*?)*"([,}]\s*)
Can anyone give me help, please ?
CodePudding user response:
Try this: ^:[\s\S] ?,$
Demo: https://regex101.com/r/GSjMk8/2
Matches every line which start with :
and ends with ,
CodePudding user response:
I finally found the solution after some days of research :).
I just need to allow colons to be matched by replacing this [^:"]
with this [^"]
. And that works well.
So the entire regex looks like this if someone is facing the same problem:
:(\s )"([^"]*?(:?[^"]:)?[^:]*?)"([^:"]*?(:?[^"]:)?[^:"]*?)"([,}]\s*)