2011-01-24 05:50:11  浏览:1710

java 正则表达式

import java.util.regex.*;

class Regex1{
 public static void main(String args[]) {
  String content="For my money, the important thing "+"about the meeting was bridge-building";
  String regEx="a|f"; //表示a或f 
  Pattern p=Pattern.compile(regEx);
  Matcher propsMatcher=p.matcher(content);
  while(m.find()){
      int startIndex = propsMatcher.start(); // index of start
      int endIndex = propsMatcher.end(); // index of end + 1
      // retrieve the matching substring
       String currentMatch = content.substring(startIndex, endIndex);
    System.out.println(currentMatch);    
   }
 }

返回首页