看板 java 關於我們 聯絡資訊
大家好 ! [193] [193] [196] [196] [196] [195] int find = 193; Pattern p = Pattern.compile(Integer.toString(find)); Matcher m = p.matcher(RGB); while(m.find()){ System.out.println(m.find()); System.out.println (m.groupCount()); } output: System.out.print(m.find()) //輸出會是True 可是我 System.out.print(m.groupCount()) //輸出卻是 0 這是為什麼呢 ?? 另外補充問一個問題 如果我想用 Pattern.compile比對 字串是:"[193]" 我使用 Pattern.compile("["+String.valueOf(i)+"]") 輸出反而變成 1:1 1:2 1:3 1:4 1:5 3:1 3:2 5:1 5:2 5:3 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.24.124.2
adrianshum:你把 RGB 的 pattern 也放上來會不會比較好? 01/27 12:52
已補上 ※ 編輯: j999444 來自: 114.24.124.2 (01/27 13:22)
PsMonkey:==" [] 在 RegExp 不是有特定意義? 01/27 13:49
是呀 所以我要怎麼比對 "[193]" 這個字串 ..?? ※ 編輯: j999444 來自: 114.24.124.2 (01/27 14:02)
coolcomm:"\\[193\\]" 01/27 14:52
PsMonkey:這裡不是讓你問 know what 的地方 01/27 15:15