Java正则解析HTML一例
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
static String teststr = "UAPPROJECT_ID='402894cb4833decf014833e04fd70002 ; \n\r */' select ";
/**
* 包含回车换行符的处理
*/
public static void testa(){
Pattern wp = Pattern.compile("'.*?'", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher m = wp.matcher(teststr);
String result = m.replaceAll("");
System.out.println("result:" + result);
}
/**
* 包含回车换行符的处理
*/
public static void testb(){
String result = teststr.replaceAll("(?s)'.*?'", "");
System.out.println("result:" + result);
}
public static void testc() {
String a = "abc \r\n您的查询码为:20160302175452496865,请妥善保存!\r\n def";
String b = a.replaceAll("(?s).*您的查询码为:", "").replaceAll("(?s),请妥善保存!.*", "");
System.out.println("result:" + b);
}
public static void main(String[] args) {
testa();
testb();
testc();
}
}
最新文章
- 简单测试flume+kafka+storm的集成
- PNG使用技巧 PNG的使用技巧
- centos linux安装telnet 过程及问题(源于内部tomcat网站,外部无法访问)
- sql server 2008 跨服务器查询
- 最长公共子序列 LCS
- Apache Commons 常用工具类整理
- 【bzoj1061】 Noi2008—志愿者招募
- 包含Blob字段的表无法Export/Import
- Linux SCP 命令: 利用SSH传输文件
- oracle学习----trace文件
- 【动态规划】XMU 1583 Sequence
- Nginx源码研究一:NGINX模块启动
- 安装nginx+ngx_lua支持WAF防护功能
- 刚开始学python——数据结构——“自定义队列结构“
- VueRouter和Vue生命周期(钩子函数)
- web前端学习python之第一章_基础语法(一)
- 云笔记项目-Spring事务学习-传播MANDATORY
- redis-dump安装与导出redis数据
- python常用库函数 - 备忘
- SQL Server 性能优化实战系列(二)