Today I learnt about how to use the \B
gadget in Python regular expressions. I've previously talked about the usefulness of \b
but there's a big benefit to using \B
sometimes too.
What \b
does is that it is a word-boundary for alphanumerics. It allows you to find "peter" in "peter bengtsson" but not "peter" in "nickname: peterbe". In other words, all the letters have to be grouped prefixed or suffixed by a wordboundry such as newline, start-of-line, end-of-line or a non alpha character like (
.