Regex for one or more words separated by spaces

前端 未结 2 693
孤城傲影
孤城傲影 2020-12-09 04:27

I am looking for a regex where i have one or more words (possibly should cover alpha numeric also) separated by spaces (one or more spaces)

  1. \" Test This stuff
相关标签:
2条回答
  • 2020-12-09 04:33

    I think you need something like this,

    ^\s*[A-Za-z0-9]+(?:\s+[A-Za-z0-9]+)*\s*$
    

    DEMO

    OR

    ^(?:\s+[A-Za-z0-9]+)+\s+$
    

    DEMO

    0 讨论(0)
  • 2020-12-09 04:43

    If you do not care just how many words you have, this would work:

    [\w\s]+
    

    \w is any alphanumeric. Replace it with a-zA-Z if you need only letters.

    0 讨论(0)
提交回复
热议问题