You cannot specify the number of occurrences within a character class, as this construct is used to define a specific type of character. Inside [...] * , + ? , {1,2} treated as literals.
If you just need to combine multiple comma separated words in parentheses, use
\w*\(\w*(?:,\w*)*\)
or with the required first word:
\w+\(\w*(?:,\w*)*\) ^
See regex demo (or this one ).
In Java, use String re = "\\w+\\(\\w*(?:,\\w*)*\\)"; .
Template Details :
\w* - characters + + +\( - one literal (\w* - characters + + +(?:,\w*)* - zero or more sequences ( (?:...) and (...) define sequences or alternative sequences, if | used inside groups) with a comma and 0+ characters\) - letter )
source share