2012-11-15 25 views
0

正則表達式是(\\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}) ([^\\[]+)

所以我很困惑,尤其是([^\\[]+)\\[([^\\]]+)]: (.+)部分。 謝謝。

+2

你能解釋一下你想用正則表達式來達到什麼目的嗎?你的例子很有趣,但無助於理解你需要什麼。 – AlexR

+0

此外,請提及您想使用正則表達式的位置。有許多不同的正則表達式方言,所以正則表達式的含義取決於您使用的是哪種軟件。# – sleske

+0

對於Java,我建議您使用此在線測試程序:http://www.regexplanet.com/advanced/java /index.html – jlledom

回答

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); 
} 
+0

How你有沒有得到**完整的清單? –

+0

它由我自己的一些代碼組成,我使用了一些隨機字符生成器和http://code.google.com/p/xeger/,我將表達式分成5個部分並分別生成每個部分以將它們連接在一起。由於外部依賴關係,我沒有發佈代碼。 – epoch

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]:...'

的括號表示的基團。

+0

but ** oo [pp] ... ** can not work with **([^ \\ [] +)\\ [([^ \\]] +)]:(。+)**根據我的測試 –

+0

如果你還沒有想出來..去這裏myregexp.com。爲正則表達式寫[^ \ [] + \ [[^ \]] + \]:。+這是你的正則表達式,沒有分組,並且寫下'oo [pp]:...'你會看到它匹配 – ddarellis