On Mar 19, 10:33 pm, [EMAIL PROTECTED] wrote: > hi > how can i use regexp to group these digits into groups of 3? > > eg > line 123456789123456789 > > i have : > > pat = re.compile("line\s+(\d{3})" , re.M|re.DOTALL) > > but this only gives the first 3. I also tried > > "line\s+(\d{3})+" > but also not working. > I need output to be ['123' ,'456','789', '123','456','789', .....] > thanks.
Try: import re target_string = """not 123456789 but try this line 987654321""" try: digits = re.compile(r'line\s+(\d +)').search(target_string).group(1) except AttributeError: digits = '' three_at_a_time = re.compile(r'\d{3}').findall(digits) print three_at_a_time -- Hope this helps, Steven -- http://mail.python.org/mailman/listinfo/python-list