"<" special character in re?
Opinderjit
bhellao at my-deja.com
Mon Sep 18 10:17:17 EDT 2000
Try using re.search instead of re.match.
re.match matches only from the beginning of a string, and re.search
scans through the string finding the first match.
For example, the re.match will match the string '<hh>ab<cd>ef', with
group('i') equal to '<hh>'.
The Python Library Reference (part of the HTML docs that come with the
install) contains a section on Matching vs. Searching (Section 4.2.2).
Hope this helps.
In article <8FB39D54Astefanwitzelzvwunigo at 134.76.98.67>,
stefan.witzel at zvw.uni-goettingen.de (Stefan Witzel) wrote:
> When I try to extract all characters between "<" and ">" using re ...
>
> import re
> hit = re.match('<(?P<i>[a-z]*)>', 'ab<cd>ef')
> if hit:
> print hit.group('i')
> else:
> print 'no hit'
>
> ... I always get "no hit". Is "<" a special character in re?
>
> Thanks in advance.
>
> Stefan Witzel
>
> --
> Stefan Witzel -----------------------------------
> Universitaet Goettingen stefan.witzel at zvw.uni-goettingen.de
> Stabsstelle DV -----------------------------------
> Gosslerstrasse 5-7 fon: +49 551 394160
> 37073 Goettingen fax: +49 551 399612
> Germany -----------------------------------
>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list