PatternSyntaxException: Illegal Repetition when using regex in Java

会有一股神秘感。 提交于 2019-11-27 01:47:21
fge

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.

There should be plus operator:

user_id : [0-9]+

Double apostrophes only when the string has to contain it.

When the string including curly brackets use:

\{user_id : [0-9]+\}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!