M
Marco Herrn
Hi,
I am not very familiar with regular expressions. So I hope someone can
help me to achieve what I want.
I have the following string in my program:
string= "aaa%(BBB%(CCC)BBB)aaa%(DDD)aaa"
Now I need to extract the parts that are enclosed in %().
There are 3 levels of nesting. The first level is named
'aaa', the second 'BBB' and 'DDD' and the third 'CCC'.
I do not need to extract the third level at this moment, since I extract
the parts in a recursive function. So the thing I want to achieve here
is to extract %(BBB%(CCC)BBB) and %(DDD).
I tried it with the following:
re.search("%\(.*\)", string).group()
But that returns:
%(BBB%(CCC)BBB)aaa%(DDD)'
which is, of course, not what I want.
So how must the regex look like that I get the two strings I need?
Marco
I am not very familiar with regular expressions. So I hope someone can
help me to achieve what I want.
I have the following string in my program:
string= "aaa%(BBB%(CCC)BBB)aaa%(DDD)aaa"
Now I need to extract the parts that are enclosed in %().
There are 3 levels of nesting. The first level is named
'aaa', the second 'BBB' and 'DDD' and the third 'CCC'.
I do not need to extract the third level at this moment, since I extract
the parts in a recursive function. So the thing I want to achieve here
is to extract %(BBB%(CCC)BBB) and %(DDD).
I tried it with the following:
re.search("%\(.*\)", string).group()
But that returns:
%(BBB%(CCC)BBB)aaa%(DDD)'
which is, of course, not what I want.
So how must the regex look like that I get the two strings I need?
Marco