regular expressions with other string classes

Andrew Dalke dalke at dalkescientific.com
Wed Sep 19 03:25:20 EDT 2001


Juan Valiño:
>It is possible to use the regular expression engine with other string-like
>structures?.

Sometimes.  They work on 'array's

Python 2.2a3+ (#6, Sep 17 2001, 05:05:24)
[GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import re
>>> pat = re.compile("^(.*(?=dalke).*)$", re.MULTILINE)
>>>


>>> import array
>>> s = array.array("c", open("/etc/passwd").read())
>>> m = pat.search(s)
>>> m
<SRE_Match object at 0x1202d1430>
>>> m.group(1)
array('c', 'dalke:*:100:100:Andrew Dalke:/home/dalke:/bin/tcsh')
>>>

but they don't seem to work with memory mapped files.  (Hard to
tell, since I always get confused working with the mmap file.
Indeed, just caused a bus error on Linux playing around with this.
Now to report the problem on sf.)

                    Andrew
                    dalke at dalkescientific.com







More information about the Python-list mailing list