A regular expression matches three words separated by two commas

I try to get at least three words separated by two commas. I managed to combine two words with one comma using

/([A-z]|[0-9])(,{1})([A-z]|[0-9])/ 

but how can I add a comma and a word to it. I tried to repeat the same, but did not work.

+5
source share
5 answers

/^(?:\w+,){2,}(?:\w+)$/

This will give you a comma-separated list of at least 3 words ([a-zA-Z0-9 _] +).

/^\s*(?:\w+\s*,\s*){2,}(?:\w+\s*)$/

This is a slightly more convenient version of the first, allowing spaces between words.

+5
source

PERL , , , /[^,]+(?:,[^,]+){2,}/ , , , - . (?:) . {2,} 2 . javascript :

/[^,]+(?:,[^,]+){2,}/.test("hello,world,whats,up,next"); // returns true

/[^,]+(?:,[^,]+){2,}/.test("hello,world"); // returns false
+1

:

  • [] | [] - [], . [A-Za-z0-9]
  • () - , . , , ( - (?:...))
0

Try the following:

([a-zA-Z0-9]+)(,[a-zA-Z0-9]+){2,}
0
source

This will solve your problem, try this.

([A-Za-Z0-9], [A-Za-Z0-9], ([A-Za-Z0-9]))

-1
source