PatternSyntaxException: Illegal Repetition when using regex in Java

The { and } are special in Java’s regex dialect (and most other dialects for that matter): they are the opening and closing tokens for the repetition quantifier {n,m} where n and m are integers. Hence the error message: “Illegal repetition”.

You should escape them: "\\{\"user_id\" : [0-9]*\\}".

And since you seem to be trying to parse JSON, I suggest you have a look at Jackson.

Leave a Comment