正则表达式为(\\w+).*>(.{23}) ([^\\[]+)\\[([^\\]]+)]: (.+)
Pattern pattern = Pattern.compile("(\\w+).*>(.{23}) ([^\\[]+)\\[([^\\]]+)]: (.+)")
String s = "xxxxxx"; //this is what I want
Matcher matcher = pattern.matcher(s);
System.out.println(matcher.find()); // I hope "true"
也许这不适合在这里寻求帮助。但我不是正则表达的专家,我需要快速了解结果。
我降低了复杂性并尝试了一些方案。
abbb>(ccccccccccccccccccccddddddddddcc)
可以(\\w+).*>(.{23})
(\\a)
可以([^\\[]+)
但如果我将它们合并。
abbb>(ccccccccccccccccccccddddddddddcc) (\\a)
不适合(\\w+).*>(.{23}) ([^\\[]+)
所以我很困惑,尤其是([^\\[]+)\\[([^\\]]+)]: (.+)
部分。
谢谢。
答案 0 :(得分:0)
([^\[]+) is what ever exept '[' one or more times
\[([^\]]+)]: (\.+) '[' what ever except ']' one or more times ']' : a space and
one ore more dots
与此匹配的示例是'oo [pp]:...'
括号代表组。
答案 1 :(得分:0)
你的问题很不清楚,但是如果你需要字符串来匹配你的正则表达式,我会为你做一些:
matches:true, string:word-0>kiOgNnuGfalhTfkqxtsCyhN f[RxQrH]: tqtmY matches:true, string:word-1>wlnJomNExhCLHjrmsyLsKhh g[fXSsPYD]: BbzUM matches:true, string:word-2>pdTepooJdeDgnODUAJMMPtB Pf[d]: aqmYx matches:true, string:word-3>jMNDTuvCBufSEAxuzPDmyFG xt[T[RJjQEpJ]: bdlLS matches:true, string:word-4>kHwqbjwNrSqhGeutzxtqiEy f[SmjJVt]: dWwlU matches:true, string:word-5>UreUxUwpIyHqPXqVlALIlmr vuJScq[QFIpLCplW]: UuL0K matches:true, string:word-6>dojPDeXqAfsHvGjOfvyZOtR aq[ImRqDn]: eyqlr matches:true, string:word-7>ViljtcHRPzMjktFzqwDcprB le[U]: yfohG matches:true, string:word-8>sjtQoCTupFbYqzhxcnrPbMh hhR[gufba]: DmREu matches:true, string:word-9>ZauFhTHuvuXcqlymybjYHzj yv[FAaupu]: ZtrqL
所有这些都匹配"(\\w+).*>(.{23}) ([^\\[]+)\\[([^\\]]+)]: (.+)"
,该列表是由我写的一些代码生成的:
// generate some strings....
for (String string : full) {
Pattern pattern = Pattern.compile("(\\w+).*>(.{23}) ([^\\[]+)\\[([^\\]]+)]: (.+)");
Matcher matcher = pattern.matcher(string);
System.out.println("matches:" + matcher.find() + ", string:" + string);
}