let say i have a string like this "neverMind<b>What is up</b>neverMind" and I want to take out the What is up using regexp with JAVA. Someone told me that using matcher will be the best. Can anyone show me how to do it using Matcher?
Other solutions are welcome too! Thanks!

假设我有一个像这样的字符串“neverMindWhat is upneverMind”,我想把regexp与JAVA结合使用的内容去掉。有人告诉我使用matcher是最好的。谁能告诉我如何使用Matcher吗?其他的解决方案也很受欢迎!谢谢!

1 个解决方案

#1


3

If your string is simple like this all the time, you could use the java Pattern indeed. But if your strings get more complicated and you want to extract contents from nested structures, you should really use a HTML parser.

如果您的字符串一直像这样简单,那么您确实可以使用java模式。但是,如果您的字符串变得更复杂,并且希望从嵌套结构中提取内容,那么您应该使用HTML解析器。

For choosing the right parser look at this question: Which HTML parser is best.

要选择正确的解析器,请查看这个问题:哪个HTML解析器是最好的。

If you stay with patterns, your regex will look like this:

如果您继续使用模式,您的regex将如下所示:

Pattern pattern = Pattern.compile( "<b>(.*?)</b>" );
Matcher m = pattern.matcher( "neverMind<b>What is up</b>neverMind" );
if( m.find() ) {
    String theStringYouAreLookingFor = m.group( 1 );
}

更多相关文章

  1. js去掉html标签和去掉字符串文本的所有的空格
  2. HTML5用户身份认证源代码:注册、登录、会话保持的解决方案
  3. 用于在表中强制换行的PHP或HTML/CSS解决方案
  4. knitr html输出中的字符串太长
  5. 从数组中构建越来越长的字符串
  6. 如何解析命令行字符串来使用regex获取每个参数?
  7. 如何实现分布式文件上传解决方案?
  8. php逐个汉字遍历字符串
  9. php 把驼峰样式的字符串转换成下划线样式的字符串

随机推荐

  1. android滑动菜单SlidingMenu
  2. Android BroadcastReceiver中播放提示语
  3. linux android 如何把android项目打成jar
  4. android异步的几种方式
  5. Android中有时候运行程序的时候会报错:An
  6. 仿微信公众号界面实现
  7. . lang。例:Rect应该与child的界限相交。
  8. 安卓中无限轮播的实现
  9. 【Camera】Android平台Camera实时滤镜实
  10. Say Hello To Android(解析Android项目目