[Python-ideas] Proposed convenience functions for re module

Ron Adam rrr at ronadam.com
Thu Jul 23 11:14:20 CEST 2009



Steven D'Aprano wrote:
> On Wed, 22 Jul 2009 06:02:54 pm Ron Adam wrote:
>> One of the needs I've run across is to enable the program user
>> (possibly a non-programmer) to do logical searches on data.
>>
>> It would be nice if the search patterns specified by the program user
>> could be used directly by the functions.  Search functions of this
>> type would take patterns that are more like what you would use for
>> google or yahoo searches instead of the more complex language re
>> requires.
> 
> I'm not sure if I understand this correctly. Perhaps you could give an 
> example or two?
> 
> Also, please don't overload my simple little proposal with a multitude 
> of new functionality. My proposal is only meant to be a lightweight 
> convenience function. Additional functionality probably belongs as a 
> different function, maybe even a different module.




Yes, it would be a different module and not added directly to the re 
module.  While you are thinking of simplifying re for programmers, I'm 
thinking of simplified searches for users.  A different target and purpose.

I think your functions would make this idea easier to do.


It would be nice if we could do simple logical searches where.

      [word1 word2]            ;get results with either word1 or word2
      [+word1 +word2]          ;get results with both word1 and word2
      [word1 -word2]           ;get results with word1 and not with word2
      ["word one" "word two"]  ;use quotes to search for phrases

And possibly use '*' and '?' as simple wild cards but keep it easy to use 
and simple.  More complex searches should use the re module directly.

This would act as a filter for lists and would be suitable for adding a 
*simple* user search capability to many scrips and applications.

An example would be to enhance pydocs search of the summery lines. 
Currently if you type "modules key", if the key is multiple words, it only 
searches on the first word.  You can not do searches on multiple words or 
exclude results with certain words.

While we could allow regular expression input to work, for many 
applications it is overkill and it is too complex for many users.  For 
example I would not like to try and teach my parents all the subtleties of 
regular expressions when they are struggling to understand a lot more basic 
things.  They don't want to learn how to program computers, they just want 
to get a recipe that has [+chicken +"tomato sauce" -onions].

Ron


















More information about the Python-ideas mailing list