How to know what re.sub took?

Bruce Wolk bawolk at pacbell.net
Wed Apr 12 07:33:07 CEST 2000


Try this:

>>> rex.findall(st)
['hans']

There would be more elements in the list if there were more matches
made.

>>> st = "max hans bill fred"
>>> rex.findall(st)
['hans', 'fred']

Cheers, Bruce

Per Kistler wrote:
> 
> Hello
> 
> How to know what has been substituted away, if one does something like:
> 
>  >>> import re
>  >>> rex = re.compile(r"(hans|fred|simon)")
>  >>> st = "max hans bill"
>  >>> st2 = rex.sub("",st)
>  >>> st2
> 'max  bill'
> 
> It took "hans" away, but how can I learn this automatically?
> 
> Thanks, Per.



More information about the Python-list mailing list