开发者

Regexp get related words separated by blanks

I have the following Regexp that matches every word with 3 characters at least and maximum of 15.

\w{3,15}

Im stucked trying to create one for the following case, i would like to match when:

  • Every words should have 3 chars at least with a maximum of 15.
  • The separator between keywords should be blank space.
  • And the number of words should be from 1 to 4 at maximum.

keyword1 kw2 keywordnumber3 keywordn4 -> this matches

keyword1 kw2 keywordnumber3 keywordn4 kw5 -> this doesnt

keyword1,kw2,keywordnumber3,keywordn4,kw开发者_如何学编程5 -> this doesnt

keyword1 kw2 keywordnumber3 k -> this doesnt

Could you give me a hand?


^\s*\w{3,15}(\s+\w{3,15}){0,3}\s*$
  • starting and ending spaces are allowed
  • at least one {3,15} chars word
  • followed by 0 to 3 other words, preceded with 1 (or more) spaces

Note: space is \s (space, TAB, CR). Replace '\s' with ' ' (space) if you only want spaces.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜