My input string is of the form: String input = "(?,?,?)";
I am not able to come up with a valid regex to identify such strings
I have tried with following regex:
String regex = "(\\?,*)";
Assertion fails with the above regex for input strings such as (?,?) or (?,?,?,?)
You could match (?
and then repeat 1+ times ,?
and match )
.
If a single question mark is also valid, you could change the quantifier from +
to *
\(\?(?:,\?)+\)
Explanation
\(\?
Match (?
(?:,\?)+
Non capturing group, repeat 1+ times ,?
\)
Match )
In Java
final String regex = "\\(\\?(?:,\\?)+\\)";
Regex demo | Java demo
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