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
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
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
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
>>> 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