Regular expression to match a #

John Machin sjmachin at lexicon.net
Thu Aug 11 22:30:53 CEST 2005


Duncan Booth wrote:
> John Machin wrote:
> 
> 
>>>Alternatively for C style #includes search for r'^\s*#\s*include\b'.
>>
>>Search for r'^something' can never be better/faster than match for 
>>r'something', and with a dopey implementation of search [which
>>Python's re is NOT] it could be much worse. So please don't tell
>>newbies to search for r'^something'.
>>
> 
> Search for r'^something' is always better than searching for r'something' 
> when the spec requires the search to match only at the start of a line (on 
> the principle that code that works is better than code which doesn't).
> 
> It appears that this may be something the original poster wanted, so I 
> stand by my suggestion.


We could well be lost in a semantic fog where at least one of us is 
using "match" to mean "the match() method" and at least one of us is 
using match to mean soemthing like "the outcome of using a search() 
method [or a match() method]".

So I'll stand by my suggestion, too.




More information about the Python-list mailing list