Search code examples
pythonjython

extract characters between parenthesis with conditions


a = '{a=[],b=[],c=[ab=cd,ef=gh],d=[ij=kl],e=[]}'

How can I extract characters between parenthesis [ ] from above string that are after =. Output expected is:

'cd','gh','kl'

Solution

  • Use regex to capture the string in [] with = between

    import re
    result = re.findall(r'\w+=(\w+)', a)
    

    \w+ will match all word with length 1 or more

    () denote a capturing group