I am trying to parse the following string and return all digits after the last square bracket:
C9: Title of object (foo, bar) [ch1, CH12,c03,4]
So the result should be:
1,12,03,4
The string and digits will change. The important thing is to get the digits after the '[' regardless of what character (if any) precede it. (I need this in python so no atomic groups either!) I have tried everything I can think of including:
\[.*?(\d) = matches '1' only
\[.*(\d) = matches '4' only
\[*?(\d) = matches include '9' from the beginning
etc
Any help is greatly appreciated!
EDIT: I also need to do this without using str.split() too.
You can rather find all digits in the substring after the last
[
bracket:If you can't use split, then this one would work with look-ahead assertion:
This finds all digits, which are followed by only non-
[
characters till the end.It may help to use the non-greedy
?
. For example:And, here's how it works (from https://regex101.com/r/jP7hM3/1):
Although - I have to agree with others... This is a regex solution, but its not a very pythonic solution.