Q:

python finding substring inside string

I am trying to find the number of occurrences of a substring in a string inside python. But i need my search to be very specific. Before searching for the substring I remove all the punctuation:
myString.translate(None, string.punctuation)
Now I search for the substring. If I am searching for the substring "hello bob" and inside the string I am searching I have the text "hello bob—something else" or "hello bob'" along with some other text. The two characters '— are not removed when I remove the punctuation because they are non unicode characters and as a result the two strings mentioned above should not be counted as an occurrence of the word "hello bob".
I used the below regex code to try get the correct amount of occurrences, in large files (3000 lines or more) I start to not get the correct number of occurrences of the words
counter = 0
searcher = re.compile("hello bob" + r'([^\w-]|$)').search
with open(myFile, 'r') as source:
    for line in source:
        if searcher(line):
            counter += 1

Something else I tried 
I am trying to use the findAll function because so far it is giving me the correct number of occurrences for a word I enter. 
I found this on stackoverflow:
re.findall(r'\bword\b', read)
Is there anyway I can use a variable instead of word?
for example I want to use:
myPhrase = "hello bob"
re.findall(r'\bmyPhrase\b', read)

Which should be the same as:
re.findall(r'\bhello bob\b', read)

A:

You can perform string interpolating using following trick to solve the problem.
myphrase = "hello bob"
pattern = r'\b{var}\b'.format(var = myphrase)

