精華區beta java 關於我們 聯絡資訊
※ 引述《frex (Frex)》之銘言: : 關於正規表示法 : str=abc123 : str.matchs(.*123)是回傳true : 但我想要取得 符合的那串 字串 : 也就是abc123 : 查了一下api好像沒看到這個方法? : 想請問有這個方法嗎?或者要自己寫@@? import java.util.regex.Matcher; import java.util.regex.Pattern; public class Mat { public static void main(String[] args) { // compile pattern Pattern p = Pattern.compile("(.*123).*"); // get matcher Matcher m = p.matcher("abc123xc"); // test if match if (m.matches()) { System.out.println(m.group(1)); } } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.21.79.162