正则提取字符串中的字符串

String regEx = "(?<=\\[)[\\S\\s]+(?=\\])";
Pattern p = Pattern.compile(regEx);
Matcher m = p.matcher(line);
boolean result = m.find();
System.out.println(m.group());

 

 

 

 

public class RegexTest {

  /**
  * @param args
  */
  public static void main(String[] args) {
  // TODO Auto-generated method stub
  String str = "<input type='text' id='baijinshan' name='baijinshan' >";
// 正则表达式:以id='开头,以' name结尾。
  String regEx="(?<=id=')[\\S\\s]+(?=' name)";
  Pattern p=Pattern.compile(regEx);
  Matcher m=p.matcher(str);
  boolean result=m.find();
  System.out.println(m.group());
  }

}

posted on 2017-06-03 23:54  adolfmc  阅读(894)  评论(0编辑  收藏  举报