java使用正则表达式匹配和提取字符

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/XUEER88888888888888/article/details/84485690
  1.匹配字符串
public static boolean isLegalInputLine(String line )   {

        Pattern p =Pattern.compile("GraphType\\s*=\\s*\".+\"\\s*");
     	Matcher m = p.matcher(line);
    	boolean r =m.matches(); 
    
    	return r;
    	
    }
 2.匹配并提取字符串
public List<String> getString(String s) {

   List<String> strs = new ArrayList<String>();
   Pattern p = Pattern.compile("GraphType\\s*=\\s*\".+\"\\s*");
   Matcher m = p.matcher(s);
   while(m.find()) {
     strs.add(m.group());

   }
   return strs;
}

猜你喜欢

转载自blog.csdn.net/XUEER88888888888888/article/details/84485690