Regex To Match The First Word Of Each Line In A Multiline Text Block

A regular expression to match the first word of each line in a multiline text block (excluding spaces).



  • ^ Beginning. Matches the beginning of the string, or the beginning of a line if the multiline flag (m) is enabled.
  • \w Word. Matches any word character (alphanumeric & underscore).
  • + Quantifier. Match 1 or more of the preceding token.
  • g Global.
  • m Multiline.


  • This Is A Sentence.
  • This Is A Sentence.
  • This Is A Sentence.


  • Any spaces found in a string

See Also: