Regex Help - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Regex Help (/thread-5071.html) |
Regex Help - mp3909 - Sep-17-2017 >>> name = re.compile(r'hello') >>> mo = name.search('They shouted out hellop to the crowd') >>> mo.group() 'hello'how can I achieve a strict match of the word 'hello' and not 'hellop' in the above example? RE: Regex Help - ichabod801 - Sep-17-2017 name = re.compile('hello\b') \b matches the empty string at a word boundary. This will still match 'shello', but you could put a \b at the beginning to stop that too.
|