[Tutor] Regexes -- \b ; re.sub
Magnus Lycka
magnus@thinkware.se
Mon Nov 18 05:56:03 2002
At 16:30 2002-11-18 +0630, John Abbe wrote:
>Nice to know i can be original :). I'm learning mostly from the O'Reilly
>pocket reference, so i'm making a lot of things up as i go along. I was
>wondering why it was so cumbersome.
:)
You didn't invest in the thickest book available... The
library reference is your friend... Obviously, the result
of being "original", if that means writing programs that
work by accident (or rather due to trial and error) and
not because they are "correct" is that it might break in
the next version of Python. So far, Guido hasn't hesitated
to make Python more strict in following the documented
behaviour. For instance you could once write
l = []
l.append(1, 2, 3)
instead of
l.append((1, 2, 3))
as you should. A lot of programs stopped working when that
"bug" was fixed. There was also a function in the socket
library that fixed in the same way, with the same result.
I'm sure we are all guilty of sometimes "testing what works",
rather than studying what's supposed to work, but there is
certainly a danger in his.
>>I'm not sure why you called your match object "matches". If you want
>>to find all non-overlapping <something><word boundry><something> you
>>could use re.findall(pattern, text) or re.compile(pattern).findall(text)
>
>Since i had more than one parentheses, i was thinking of it as multiple
>matches. I guess the Python lingo for that would be "groups" and "matches"
>would be what you're describing here.
Ok, fine. I just though that maybe you expected it to act
like findall.
--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se