Python Regex - Match and Start()
Question: Let's say I need to find the word "water" in a string. This word cannot be
part of another word and it can't be preceded by punctuation (so i'm assuming
it can only be preceded by a " " or it's the beginning of the string). I need
to return the index of the word's first char "w". So I'm trying this code :

    
    
    import re
    s = re.search(r"(\A| )\bwater\b", "Need water") 
    return s.start() # This returns the index of the char " " :(
    

Is it possible to ignore the **(\A| )** part of the pattern so that s.start()
always returns the index of the char "w"? Or am I thinking this wrong?


Answer: You can use

    
    
    (?<!\S)\bwater\b
    

See the [regex demo](https://regex101.com/r/eT5vS1/1)

**Explanation:**

  * `(?<!\S)` \- a negative lookbehind failing a match if there is a non-whitespace character right before a whole word `water`
  * `\bwater\b` \- a whole word `water`.

Here is a [Python demo](http://ideone.com/vy1li5):

    
    
    import re
    s = re.search(r"(?<!\S)\bwater\b", "Need water") 
    if s:
        print(s.start())
    

