regex, repeating group
Steven Taschuk
staschuk at telusplanet.net
Fri May 30 16:06:47 EDT 2003
Quoth Steven Scott:
> say I'm working with this:
> str = """body body body
> -><-
> Meeting Info
> From:you
> Attendees:me
> Date:now
> ID:0"""
>
> I have this regular expression to get the data after colons, which I'm using
> in re.search:
>
> regex = r'-><-\n.+?\n(?:.+?:(.*?)\n?){4}$'
[...]
Not answering your question, but code such as
lines = s.split('\n')
for i in range(len(lines)):
if lines[i] == '-><-':
data = []
for dataline in lines[i+2:i+6]:
key, value = dataline.split(':', 1)
data.append(value)
# do something with data
is clearer imho than any regular expression for this purpose.
--
Steven Taschuk staschuk at telusplanet.net
"Its force is immeasurable. Even Computer cannot determine it."
-- _Space: 1999_ episode "Black Sun"
More information about the Python-list
mailing list