I\'m having trouble finding the correct regular expression for the scenario below:
Lets say:
a = \"this is a sample\"
I want to mat
Try using the "word boundary" character class in the regex module, re
:
x="this is a sample"
y="this isis a sample."
regex=re.compile(r"\bis\b") # For ignore case: re.compile(r"\bis\b", re.IGNORECASE)
regex.findall(y)
[]
regex.findall(x)
['is']
From the documentation of re.search().
\b
matches the empty string, but only at the beginning or end of a word...
For example
r'\bfoo\b'
matches'foo'
,'foo.'
,'(foo)'
,'bar foo baz'
but not'foobar'
or'foo3'