Re: spaces in re.compile()

2005-03-21 Thread rbt
Jeff Epler wrote: Maybe you want r'\b'. From 'pydoc sre': \b Matches the empty string, but only at the start or end of a word. import re r = re.compile( r'\btest\b' ) print r.findall("testy") print r.findall(" testy ") print r.findall(" test ") print r.findall("test") That works great. T

spaces in re.compile()

2005-03-21 Thread rbt
Is it possible to use spaces in a re.compile()? For example, I want to make sure one space exists right before this string and right after it: re.compile ('\d{3,3}\.\d{3,3}\.\d{3,3}\.\d{3,3}') I've tried this, but it didn't work: re.compile (' \d{3,3}\.\d{3,3}\.\d{3,3}\.\d{3,3} ') Any ideas? -- h

Re: spaces in re.compile()

2005-03-21 Thread Jeff Epler
Maybe you want r'\b'. From 'pydoc sre': \b Matches the empty string, but only at the start or end of a word. import re r = re.compile( r'\btest\b' ) print r.findall("testy") print r.findall(" testy ") print r.findall(" test ") print r.findall("test") pgps8PNW4uDgh.pgp Description: PG

Re: spaces in re.compile()

2005-03-21 Thread rbt
AndrewN wrote: d = re.compile(' \d{3}\.\d{3}\.\d{3} ') d.findall(' 123.345.678 ') [' 123.345.678 '] Works for me. Yes, you're correct. That works if there is a space at the front and back. However, place '123.345.678' in a file by itself and it doesn't work. What I'm trying to avoid is something

Re: spaces in re.compile()

2005-03-21 Thread AndrewN
>>> d = re.compile(' \d{3}\.\d{3}\.\d{3} ') >>> d.findall(' 123.345.678 ') [' 123.345.678 '] Works for me. -- http://mail.python.org/mailman/listinfo/python-list