[英]java regex parsing error
i would like to use this regex in java我想在 java 中使用这个正则表达式
^class QuineHash.*?{(.*?(\s))*}$
However when i launch the function it throws an illegal repetion error.但是,当我启动该功能时,它会引发非法重复错误。
These are the commands:这些是命令:
String pattern = "^class QuineHash.*?{(.*?(\\s))*}$";
Pattern r = Pattern.compile(pattern);
This is the error:这是错误:
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 18
^class QuineHash.*?{(.*?(\s))*}$
How can i solve the problem?我该如何解决问题?
EDIT:编辑:
I solve the problem simply by changing the previous regex with this one:我简单地通过用这个改变以前的正则表达式来解决这个问题:
class QuineHash(?:.*?\\s)*}
String pattern = "^class QuineHash.*?\{(.*?(\\s))*\}$";
逃离大括号!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.