3

I am trying to match all instances of the pattern in the string using Python. However, when the patterns overlap I get only the longest one, while I need both:

import re
st = '''GYMGMTPRLGLESLLEStopAS'''
w = re.findall("M\w*?(?=Stop)",st)
print w

Output:

1. MGMTPRLGLESLLE

Desired output:

1. MGMTPRLGLESLLE
2. MTPRLGLESLLE
brandonscript
  • 68,675
  • 32
  • 163
  • 220
user3468837
  • 47
  • 1
  • 4
  • 1
    possible duplicate of [Python regex find all overlapping matches?](http://stackoverflow.com/questions/5616822/python-regex-find-all-overlapping-matches) – Jerry Mar 27 '14 at 18:27
  • This is probably a significant variant of that one. –  Mar 27 '14 at 18:45

1 Answers1

4

(?=(M\w*?)Stop) Then the overlapp data is in capture group 1.