check object being a compiled regular expression

Helmut Jarausch jarausch at skynet.be
Sat Mar 25 10:58:09 EST 2006


Hi,
sorry, this seems to be a FAQ but I couldn't find anything

I need to check if an object is a compiled regular expression

Say
import re
RX= re.compile('^something')

how to test

"if RX is a compiled regular expression"

type(RX)  says
<type '_sre.SRE_Pattern'>

but

if isinstance(RX,_sre.SRE_Pattern)
and
if isinstance(RX,re._sre.SRE_Pattern)
both fail.

Many thanks for a hint,

Helmut Jarausch

Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany



More information about the Python-list mailing list