使用正则表达式从字符串中查找子字符串

前端之家收集整理的这篇文章主要介绍了使用正则表达式从字符串中查找子字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

直接上代码

  1. String string = "asdasd#_%12.gifdadsa#_%2324.gif";
  2. String regx = "#_%\\d+.gif";
  3. Pattern pattern = Pattern.compile(regx,Pattern.CASE_INSENSITIVE);
  4. Matcher matcher = pattern.matcher(string);
  5. while(matcher.find()){
  6. System.out.println(matcher.group());
  7. }

猜你在找的正则表达式相关文章