JAVA中用正则表达式做全文查找

来源:互联网 发布:文件防拷贝软件 编辑:程序博客网 时间:2024/04/30 19:15

 

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);   
   }
 }
}