How can you make \b accept words that start with '+' using regex in python?
Question: 
    re.search(r"\b\+359\b","Is your phone number +359 887438?")
    

Why is this regex not finding `+359` and how can i make `\b` consider words
starting with `+`?


Answer: You can't alter `\b`'s behaviour. You'd have to use a different anchor; like
`\B`, which matches anywhere _not_ at the start or end of a word; it is the
inverse of `\b`:

    
    
    \B\+359\b
    

This again matches if there is no word character preceding `+`, which itself
is a non-word character. Where `\b` can only match between a word and nonword
character (so `WORD\bNONWORD` or `NONWORD\bWORD`), `\B` needs two nonword or
two word characters to match (so `WORD\BWORD` or `NONWORD\BNONWORD`). As `+`
is a nonword character, whatever comes before `+` must _also_ be a non-word
character.

Alternatively, you can use a negative look-behind:

    
    
    (?<!\w)\+359\b
    

The `(?<!\w)` negative look-behind assertion only matches a position where
there is no word character preceding the position.

Demo:

    
    
    >>> import re
    >>> re.search(r"\b\+359\b","Is your phone number +359 887438?")
    >>> re.search(r"\B\+359\b","Is your phone number +359 887438?")
    <_sre.SRE_Match object at 0x10cf03850>
    >>> re.search(r"(?<!\w)\+359\b","Is your phone number +359 887438?")
    <_sre.SRE_Match object at 0x10cf03d30>
    

