I am new to python and am trying to parse a long text string for sub-strings between two exact patterns. The problem lies in telling python to stop at the first occurrence of the end pattern. I also need to collect all instances of the sub-strings into place them into an array storage to be used later on. I am trying to utilize the (re) module example here by Nikolaus Gradwohl for simplicity. Below is an example of what I have done.
import re
string='valuepattern1":"capture",abcdpattern1":"capture2",defg'
result = re.search('pattern1":"(.*)",', string)
print result.group(1)
Output: capture",abcdpattern1":"capture2"
Here I am trying to collect every instance of capture (capture and capture2) found in the string between the set beginning point of (pattern1":") and the immediate ending point (",) after capture. Each instance collected needs to be added to an array, as shown below.
print result
Output: [capture,capture2]
Note that capture does not have a set length and varies all throughout the string, however, the beginning and ending patterns remain consistent through the string.
Thank you in advance for any help on this matter.