RE Help

chris.monsanto at gmail.com chris.monsanto at gmail.com
Fri Sep 21 16:44:26 EDT 2007


On Sep 21, 4:09 pm, Thomas Jollans <tho... at jollans.com> wrote:
> On Friday 21 September 2007, byte8b... at gmail.com wrote:
>
> > Not specific to Python, but it will be implemented in it... how do I
> > compile a RE to catch everything between two know values? Here's what
> > I've tried (but failed) to accomplish... the knowns here are START and
> > END:
>
> > data = "asdfasgSTARTpruyerfghdfjENDhfawrgbqfgsfgsdfg"
> > x = re.compile('START.END', re.DOTALL)
>
> > x.findall(data)
>
> I'm not sure finding a variable number of occurences can be done with re. How
> about
>
> # data = the string
> strings = []
> for s in data.split('START')[1:]:
>     strings.append(s.split('END')[0])

use re.findall :-)




More information about the Python-list mailing list