I'm sorry for asking this maybe duplicate question. I checked the existing questions and answers about optional capturing groups. I tried some things but I'm not able to translate the answer to my own example.
This are two imput lines
id:target][label
id:target
I would like to capture id:
(group 1), target
(group 2) and if ][
is present label
(group 3).
The used regex (Python regex) only works on the first line (live example on regex101).
^(.+:)(.*)\]\[(.*)
In the other examples I don't get what the regex makes a capturing group optional. And maybe the delimiter ][
used by me also mix up with my understanding problem.
One thing I tried was this
^(.+:)(.*)(\]\[(.*))?