Reputation: 323
I am writing personal information filter. When it encounters VALID phone or email replaces it with "[PRIVATE]";
Valid phone is for example '0123 45678' and '00123 45678' is invalid, but i get 0[PRIVATE] for the second one after the filtering. How do i look only at entire words using regex and \bword\b
is totally not working properly.
Upvotes: 0
Views: 49
Reputation: 336418
I'm betting that you forgot to use raw strings:
re.search("\bword\b")
finds a string that starts with a backspace character, then word
, then another backspace character.
re.search(r"\bword\b")
finds an entire word
.
Upvotes: 5