"<" special character in re?
Carsten Gaebler
cg at schlund.de
Mon Sep 18 09:51:03 EDT 2000
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?
You'll have to use re.search() because re.match() matches only the
beginning of a string (see the docs).
cg.
More information about the Python-list
mailing list