Python regex - Substring match
Question: I have a pattern

    
    
    pattern = "hello"
    

and a string

    
    
    str = "good morning! hello helloworld"
    

I would like to search `pattern` in `str` such that the entire string is
present as a word i.e it should not return substring `hello` in `helloworld`.
If str does not contain `hello`, it should return False.

I am looking for a regex pattern.


Answer: You can use word boundaries around the pattern you are searching for if you
are looking to use a regular expression for this task.

    
    
    >>> import re
    >>> pattern  = re.compile(r'\bhello\b', re.I)
    >>> mystring = 'good morning! hello helloworld'
    >>> bool(pattern.search(mystring))
    True
    

