re module methods: flags(), pattern()

Kay Schluehr kay.schluehr at gmx.net
Sun Apr 17 17:03:23 EDT 2005


Xah Lee wrote:
> Python re module has methods flags and pattern. How to use these
> exactly?

>From the Python 2.3 documentation, section 2.4.2

flags

The flags argument used when the RE object was compiled, or 0 if no
flags were provided.


groupindex

A dictionary mapping any symbolic group names defined by (?P<id>) to
group numbers. The dictionary is empty if no symbolic groups were used
in the pattern.

pattern

The pattern string from which the RE object was compiled.


Comments derived from the docs and error messages:

> e.g. i tried
>
> print patternObj.flags()
>
> and the error is some "int object is not callable".

=>  flags is an int object

>
> newpattern=re.compile(ur'\w+',patternObj.flags())
>
> also bad.

=> flags is still an int object


> similar error for patternObj.pattern().

=> pattern is a string

> (and i suppose the same for
> groupindex() )

=> groupindex is a dict

>
> thanks.
>
>  Xah
>  xah at xahlee.org
>http://xahlee.org/

The documentation is not that bad that one should not read it at all ;)


If You wrestle with regexps I can recommend an old but still usefull
little wrapper I found eventually on the "Vaults of Parnassus" which is
called reverb.py 

Ciao,
Kay




More information about the Python-list mailing list