Java讀取一個(gè)txt格式的文檔享用正則表達(dá)式匹配以下文檔會(huì)出現(xiàn)的字符這個(gè)正則應(yīng)該怎么寫(xiě)啊里面會(huì)有這種格式:\abc\{}_\%\都需要找出來(lái)在此謝謝各位前輩
2 回答

夢(mèng)里花落0921
TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超6個(gè)贊
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class RegexMatches
{
public static void main( String args[] ){
// 按指定模式在字符串查找 String line = "This order was placed for QT3000! OK?"; String pattern = "(\\D*)(\\d+)(.*)"; // 創(chuàng)建 Pattern 對(duì)象 Pattern r = Pattern.compile(pattern); // 現(xiàn)在創(chuàng)建 matcher 對(duì)象 Matcher m = r.matcher(line); if (m.find( )) { System.out.println("Found value: " + m.group(0) ); System.out.println("Found value: " + m.group(1) ); System.out.println("Found value: " + m.group(2) ); System.out.println("Found value: " + m.group(3) ); } else { System.out.println("NO MATCH"); }
}
}
添加回答
舉報(bào)
0/150
提交
取消