regexp questoin

Fredrik Lundh fredrik at pythonware.com
Sat Jun 10 03:15:03 EDT 2006


micklee74 at hotmail.com wrote:

> actually, i am doing an application that allows user to delete files by
> entering an input pattern. so if he has files that have special
> characters such as [-] or others, then i want to filter them off ....

I think you will have to define what "pattern" means here.  since you're 
  using the RE module, one would have thought that you want the user to 
be able to use RE patterns, but you obviously have something else in mind.

> the solution for re.compile(re.escape(userinput)) might work, i have to
> give it a try.

re.escape(userinput) creates a RE pattern that patches userinput 
exactly.  if that's what you want, there's no need to use regular 
expressions at all; just use the "in" operator:

     if userinput in filename:
         do something with file

</F>




More information about the Python-list mailing list