若有一組電話字串,該如何比對其中幾個數(如308)
package com.example;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sun.corba.se.spi.orbutil.fsm.Input;
public class StringPattern1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
String inputString = "0911308380"; //原始字串
Pattern pattern = Pattern.compile("308"); //比對字串308
Matcher matcher = pattern.matcher(inputString); //要拿原始字串和比對字串做比較
if(matcher.find()){
System.out.println("got it");
}else{
System.out.println("no match");
}
}
}
參考Gossip
沒有留言:
張貼留言