Now you can Subscribe using RSS

Submit your Email

2015/03/19

PatternMatcher

asd
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import java.util.regex.*;

public class UsePatternMatcher {
 public static void main(String[] args){
  String phones1 = "Justin's phone number : 0939-100391\n" + 
                      "momor's phone number : 0939-666888\n";
  
  Pattern pattern = Pattern.compile(".*0939-\\d{6}");
  Matcher matcher = pattern.matcher(phones1);
  
  while(matcher.find()){
   System.out.println(matcher.group());
  }
  
  String phone2 = "caterpillar's phone number : 0952-600391\n" + 
               "bush's phone number : 0939-550391";
  
  matcher = pattern.matcher(phone2);
  
  while(matcher.find()){
   System.out.println(matcher.group());
  }
 }
}

0 意見:

張貼留言

Coprights @ 2016, Blogger Templates Designed By Templateism | Templatelib