MyException - 我的异常网
当前位置:我的异常网» J2SE » regex.PatternSyntaxException: Look-behind group

regex.PatternSyntaxException: Look-behind group does not have an obvious maximum,该怎么处理

www.MyException.Cn  网友分享于:2013-12-27  浏览:345次
regex.PatternSyntaxException: Look-behind group does not have an obvious maximum
Java code
String str = "abc,afda,fdadfae,fdaee,fdafda,efdaf";

Matcher m = Pattern.compile("(?<=^(?:[^,]+,){5})[^,]+(?=\\b|,)").matcher(str);
if(m.find())
{
    System.out.println(m.group(0));
}


抛出异常
Java code
Exception in thread "main" java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 17
(?<=^(?:[^,]+,){5})[^,]+(?=\b|,)
                 ^
    at java.util.regex.Pattern.error(Pattern.java:1713)
    at java.util.regex.Pattern.group0(Pattern.java:2488)
    at java.util.regex.Pattern.sequence(Pattern.java:1806)
    at java.util.regex.Pattern.expr(Pattern.java:1752)
    at java.util.regex.Pattern.compile(Pattern.java:1460)
    at java.util.regex.Pattern.<init>(Pattern.java:1133)
    at java.util.regex.Pattern.compile(Pattern.java:823)
    at com.rmouse.TestMagicCard.main(TestMagicCard.java:37)



该怎样修改正则式呢?

------解决方案--------------------
^([^,]+,){5}(?<=[^,]+,)[^,]+(?=\b|,)
结果为匹配整个字符串
------解决方案--------------------
你想要匹配什么?
------解决方案--------------------
找个正则表达式的验证工具,先验证一下

百度一下,网上有的

祝楼主好运
------解决方案--------------------
这个正则挺难的,换一个试试,是表达式里面的东西有问题

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有