Regex to match first word in sentence

前端 未结 5 1240
花落未央
花落未央 2021-02-06 01:49

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,

5条回答
  •  你的背包
    2021-02-06 02:20

    [a-z]+
    

    This should be enough as it will get the first a-z characters (assuming case-insensitive).

    In case it doesn't work, you could try [a-z]+\b, or even ^[a-z]\b, but the last one assumes that the string starts with the word.

提交回复
热议问题