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.
精彩评论