I'm studying regular expression with python and I'm trying the \b notation and tried below code, my understanding is that if a word starts with "the", pattern "\bthe" should match it, but somehow it doesn't match my "text" nor "text2" string, could somebody help take a look and explain? Thanks!
In the documentation it is said "Note that formally, \b is defined as the boundary between a \w and a \W character (or vice versa), or between \w and the beginning/end of the string. This means that r'\bfoo\b' matches 'foo', 'foo.', '(foo)', 'bar foo baz' but not 'foobar' or 'foo3'".
my code:
text="the"
text2="thetree"
patn='\bthe'
m=re.search(patn, text)
print(m)
m=re.search(patn, text2)
print(m)
Output: None None