Re: Regular expression to match a #

2005-08-12 Thread Duncan Booth
John Machin wrote: >> Your wording makes it hard to distinguish what exactly is "dopey". >> > > """ > dopey implementations of search() (which apply match() at offsets 0, 1, > 2, .). > """ > > The "dopiness" is that the ^ operator means that the pattern cannot > possibly match starting at

Re: Regular expression to match a #

2005-08-12 Thread Duncan Booth
John Machin wrote: > The point was made in a context where the OP appeared to be reading a > line at a time and parsing it, and re.compile(r'something').match() > would do the job; re.compile(r'^something').search() will do the job too > -- BECAUSE ^ means start of line anchor -- but somewhat r

Re: Regular expression to match a #

2005-08-11 Thread Bryan Olson
John Machin wrote: [...] > Observation: factoring out the compile step makes the difference much > more apparent. > > >>> ["%.3f" % t.timeit() for t in t3, t4, t5, t6] > ['1.578', '1.175', '2.283', '1.174'] > >>> ["%.3f" % t.timeit() for t in t3, t4, t5, t6] > ['1.582', '1.179', '2.284', '

Re: Regular expression to match a #

2005-08-11 Thread John Machin
Devan L wrote: > John Machin wrote: > >>Devan L wrote: >> >>>John Machin wrote: >>> >>> Aahz wrote: >In article <[EMAIL PROTECTED]>, >John Machin <[EMAIL PROTECTED]> wrote: > > > >>Search for r'^something' can never be better/faster than match for >>r'som

Re: Regular expression to match a #

2005-08-11 Thread John Machin
John Machin wrote: > Devan L wrote: > >> John Machin wrote: >> >>> Aahz wrote: >>> In article <[EMAIL PROTECTED]>, John Machin <[EMAIL PROTECTED]> wrote: > Search for r'^something' can never be better/faster than match for > r'something', and with a dopey implementatio

Re: Regular expression to match a #

2005-08-11 Thread Devan L
John Machin wrote: > Devan L wrote: > > John Machin wrote: > > > >>Aahz wrote: > >> > >>>In article <[EMAIL PROTECTED]>, > >>>John Machin <[EMAIL PROTECTED]> wrote: > >>> > >>> > Search for r'^something' can never be better/faster than match for > r'something', and with a dopey implementa

Re: Regular expression to match a #

2005-08-11 Thread John Machin
Devan L wrote: > John Machin wrote: > >>Aahz wrote: >> >>>In article <[EMAIL PROTECTED]>, >>>John Machin <[EMAIL PROTECTED]> wrote: >>> >>> 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

Re: Regular expression to match a #

2005-08-11 Thread Devan L
John Machin wrote: > Aahz wrote: > > In article <[EMAIL PROTECTED]>, > > John Machin <[EMAIL PROTECTED]> wrote: > > > >>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 wor

Re: Regular expression to match a #

2005-08-11 Thread John Machin
Aahz wrote: > In article <[EMAIL PROTECTED]>, > John Machin <[EMAIL PROTECTED]> wrote: > >>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 newbi

Re: Regular expression to match a #

2005-08-11 Thread John Machin
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 wor

Re: Regular expression to match a #

2005-08-11 Thread John Machin
Jeff Schwab wrote: > John Machin wrote: > >> 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'. > > > H

Re: Regular expression to match a #

2005-08-11 Thread Aahz
In article <[EMAIL PROTECTED]>, John Machin <[EMAIL PROTECTED]> wrote: > >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

Re: Regular expression to match a #

2005-08-11 Thread Duncan Booth
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 >

Re: Regular expression to match a #

2005-08-11 Thread Jeff Schwab
John Machin wrote: > 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'. How else would you match the beginn

Re: Regular expression to match a #

2005-08-11 Thread John Machin
Duncan Booth wrote: > Dan wrote: > > >>>My (probably to naive) approach is: p = re.compile(r'\b#include\b) >> >>I think your problem is the \b at the beginning. \b matches a word break >>(defined as \w\W or \W\w). There would only be a word break before the # >>if the preceding character were a \

Re: Regular expression to match a #

2005-08-11 Thread John Machin
Tom Deco wrote: > Hi, > > I'm trying to use a regular expression to match a string containing a # > (basically i'm looking for #include ...) > > I don't seem to manage to write a regular expression that matches this. > > My (probably to naive) approach

Re: Regular expression to match a #

2005-08-11 Thread Duncan Booth
Dan wrote: >> My (probably to naive) approach is: p = re.compile(r'\b#include\b) > > I think your problem is the \b at the beginning. \b matches a word break > (defined as \w\W or \W\w). There would only be a word break before the # > if the preceding character were a \w (that is, [A-Za-z0-9_], a

Re: Regular expression to match a #

2005-08-11 Thread Tom Deco
Thanks, That did the trick... -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular expression to match a #

2005-08-11 Thread Dan
> My (probably to naive) approach is: p = re.compile(r'\b#include\b) I think your problem is the \b at the beginning. \b matches a word break (defined as \w\W or \W\w). There would only be a word break before the # if the preceding character were a \w (that is, [A-Za-z0-9_], and maybe some other c

Regular expression to match a #

2005-08-11 Thread Tom Deco
Hi, I'm trying to use a regular expression to match a string containing a # (basically i'm looking for #include ...) I don't seem to manage to write a regular expression that matches this. My (probably to naive) approach is: p = re.compile(r'\b#include\b) I also tried