I am trying to get at least three words separated by two commas.I have so far managed to match two words with one comma with
/([A-z]|[0-9])(,{1})([A-z]|[0-9])/
but how can I add a comma and a word to this.I have tried repeating the same but did not work.
The 0-9 indicates characters 0 through 9, the comma , indicates comma, and the semicolon indicates a ; . The closing ] indicates the end of the character set. The plus + indicates that one or more of the "previous item" must be present.
Semicolon is not in RegEx standard escape characters. It can be used normally in regular expressions, but it has a different function in HES so it cannot be used in expressions. As a workaround, use the regular expression standard of ASCII.
Inside a character class, the + char is treated as a literal char, in every regex flavor. [+] always matches a single + literal char. E.g. in c#, Regex. Replace("1+2=3", @"[+]", "-") will result in 1-2=3 .
/^(?:\w+,){2,}(?:\w+)$/
This will get 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 user-friendly version of the first, allowing spaces in between words.
If it's a PERL derived regex, as most implementations I've encountered, /[^,]+(?:,[^,]+){2,}/
tests well against anything that has at least two commas in it, providing that the commas have something between them. The (?:)
construct allows to group without capturing. The {2,}
construct specifies 2 or more matches of the previous group. In javascript, you can test it:
/[^,]+(?:,[^,]+){2,}/.test("hello,world,whats,up,next"); // returns true
/[^,]+(?:,[^,]+){2,}/.test("hello,world"); // returns false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With