Regex to match first word in sentence

princess of persia picture princess of persia · Feb 8, 2013 · Viewed 45.4k times · Source

I am looking for a regex that matches first word in a sentence excluding punctuation and white space. For example: "This" in "This is a sentence." and "First" in "First, I would like to say \"Hello!\""

This doesn't work:

"""([A-Z].*?(?=^[A-Za-z]))""".r

Answer

endy picture endy · Feb 8, 2013
(?:^|(?:[.!?]\s))(\w+)

Will match the first word in every sentence.

http://rubular.com/r/rJtPbvUEwx