python re.findall() question?


Here's the problem;

re.findall( "ab+" , "1111abbb111abb111" ) will return this list [ "abbb" , "abb" ] and that's ok

re.findall( "a(bc)+" , "11abcbc111abbbb11abcbcbc1" ) will return [ "bc" , "bc" ] and that's not what I need.

What reg expression do I use to get [ "abcbc" , "abcbcbc" ] ?

Thank you.

1 Answer

  • 9 years ago
    Favorite Answer

    What about "(a(?:bc)+)"? By adding the non-capturing group inside you capture group, it allows you to find the repetition of just bc. Haven't tested this but it seems okay.

    Source(s): Experience
Still have questions? Get your answers by asking now.