regex scanner question

Roman Suzi rnd at onego.ru
Tue Jun 26 15:42:35 EDT 2001


hi!

(After the PEP 260 I am not sure I can use anything less common
than things with established use practice... So I better ask.)

I've found SRE_Scanner object which gets birth from scanner()
method of SRE_Pattern object.

It is very convenient to use for finding sequential matches in loops
or otherwise:

>>> import re
>>> r = re.compile("\d+")
>>> s = r.scanner("1 2 33 4 54 56 jkjlkj 445")
>>> print s.search()
<SRE_Match object at 0x8134030>
>>> print s.search().group()
2
>>> print s.search().group()
33
>>> print s.search().group()
4
>>>

Is it standard Python feature I could safely use or will it be dropped
soon as it happened to xrange as a sequence type?

Could use of .scanner be recommended or not recommended?

BTW, generators could be very useful if applied inside regex routines.
They will make it easy to hop from ane finding to another without taking
too much memory.

Sincerely yours, Roman Suzi
-- 
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Tuesday, June 26, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "It is better to be brief than boring." _/






More information about the Python-list mailing list