matching patterns after regex?
Bernard
bernard.chhun at gmail.com
Wed Aug 12 07:53:19 EDT 2009
On 12 août, 06:15, Martin <mdeka... at gmail.com> wrote:
> Hi,
>
> I have a string (see below) and ideally I would like to pull out the
> decimal number which follows the bounding coordinate information. For
> example ideal from this string I would return...
>
> s = '\nGROUP = ARCHIVEDMETADATA\n
> GROUPTYPE = MASTERGROUP\n\n GROUP =
> BOUNDINGRECTANGLE\n\n OBJECT =
> NORTHBOUNDINGCOORDINATE\n NUM_VAL = 1\n
> VALUE = 19.9999999982039\n END_OBJECT =
> NORTHBOUNDINGCOORDINATE\n\n OBJECT =
> SOUTHBOUNDINGCOORDINATE\n NUM_VAL = 1\n
> VALUE = 9.99999999910197\n END_OBJECT =
> SOUTHBOUNDINGCOORDINATE\n\n OBJECT =
> EASTBOUNDINGCOORDINATE\n NUM_VAL = 1\n
> VALUE = 10.6506458717851\n END_OBJECT =
> EASTBOUNDINGCOORDINATE\n\n OBJECT =
> WESTBOUNDINGCOORDINATE\n NUM_VAL = 1\n
> VALUE = 4.3188348375893e-15\n END_OBJECT
> = WESTBOUNDINGCOORDINATE\n\n END_GROUP
>
> NORTHBOUNDINGCOORDINATE = 19.9999999982039
> SOUTHBOUNDINGCOORDINATE = 9.99999999910197
> EASTBOUNDINGCOORDINATE = 10.6506458717851
> WESTBOUNDINGCOORDINATE = 4.3188348375893e-15
>
> so far I have only managed to extract the numbers by doing re.findall
> ("[\d.]*\d", s), which returns
>
> ['1',
> '19.9999999982039',
> '1',
> '9.99999999910197',
> '1',
> '10.6506458717851',
> '1',
> '4.3188348375893',
> '15',
> etc.
>
> Now the first problem that I can see is that my string match chops off
> the "e-15" part and I am not sure how to incorporate the potential for
> that in my pattern match. Does anyone have any suggestions as to how I
> could also match this? Ideally I would have a statement which printed
> the number between the two bounding coordinate strings for example
>
> NORTHBOUNDINGCOORDINATE\n NUM_VAL = 1\n
> VALUE = 19.9999999982039\n END_OBJECT =
> NORTHBOUNDINGCOORDINATE\n\n
>
> Something that matched "NORTHBOUNDINGCOORDINATE" and printed the
> decimal number before it hit the next string
> "NORTHBOUNDINGCOORDINATE". But I am not sure how to do this. any
> suggestions would be appreciated.
>
> Many thanks
>
> Martin
Hey Martin,
here's a regex I've just tested : (\w+COORDINATE).*\s+VALUE\s+=\s([\d\.
\w-]+)
the first match corresponds to the whateverBOUNDINGCOORDINATE and the
second match is the value.
please provide some more entries if you'd like me to test my regex
some more :)
cheers
Bernard
More information about the Python-list
mailing list