Java使用正则表达式截取重复出现的XML字符串功能示例
作者:北环阳光 时间:2023-02-04 20:44:51
本文实例讲述了Java使用正则表达式截取重复出现的XML字符串功能。分享给大家供大家参考,具体如下:
public static void main(String[] args) throws DocumentException {
String s = "<MTCCommand Time=\"2014-03-22\"><Login UserId=\"admin\" UserPasswd=\"123\" /></MTCCommand><MTCCommand><Login/></MTCCommand>";
String regEx = "<MTCCommand((?!<MTCCommand).)*</MTCCommand>";
Pattern pat = Pattern.compile(regEx);
Matcher mat = pat.matcher(s);
while(mat.find()){
System.out.println(mat.group());
}
}
输出结果:
<MTCCommand Time="2014-03-22"><Login UserId="admin" UserPasswd="123" /></MTCCommand>
<MTCCommand><Login/></MTCCommand>
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述对大家java程序设计有所帮助。
来源:http://blog.csdn.net/lotusyangjun/article/details/22187975
标签:Java,正则表达式,XML
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python中如何引入第三方模块
2023-08-27 08:34:48
详解python第三方库的安装、PyInstaller库、random库
2023-03-13 06:57:46
![](https://img.aspxhome.com/file/2023/7/83837_0s.png)
Django实现视频播放的具体示例
2022-11-04 22:26:35
php设置编码格式的方法
2023-11-14 12:01:22
Mootools 1.2教程(8)——输入过滤第一部分(数字)
2008-11-27 13:01:00
根据选择的checkbox列出选择的值
2008-07-30 12:56:00
![](https://img.aspxhome.com/file/UploadPic/20087/30/200873013437517s.jpg)
python通过pil模块获得图片exif信息的方法
2021-08-26 14:31:21
Django框架的中的setting.py文件说明详解
2022-11-05 13:26:24
![](https://img.aspxhome.com/file/2023/2/89172_0s.png)
python文件及目录操作代码汇总
2022-08-19 14:07:27
Python随机生成均匀分布在三角形内或者任意多边形内的点
2022-02-15 22:02:14
![](https://img.aspxhome.com/file/2023/9/97629_0s.png)
Python中的Function定义方法第1/2页
2021-05-10 20:33:49
TensorFlow 2.0之后动态分配显存方式
2023-12-20 05:25:17
详细介绍Python中的偏函数
2022-12-28 08:40:53
vue实现简单全选和反选功能
2024-05-09 09:29:47
![](https://img.aspxhome.com/file/2023/2/128872_0s.gif)
Python编写可视化界面的全过程(Python+PyCharm+PyQt)
2022-02-23 02:21:36
![](https://img.aspxhome.com/file/2023/1/75261_0s.jpg)
Python自动生成代码 使用tkinter图形化操作并生成代码框架
2021-04-26 08:47:30
![](https://img.aspxhome.com/file/2023/7/95607_0s.jpg)
Mysql树形递归查询的实现方法
2024-01-14 08:05:16
Python中安装easy_install的方法
2022-06-22 20:30:00
![](https://img.aspxhome.com/file/2023/5/89165_0s.png)
MySQL数据库的双向加密方式
2009-11-18 11:07:00
python+Django+apache的配置方法详解
2021-02-18 06:39:06