JAVA replaceAll 正则表达式(持续更新)
来源:互联网 发布:互联网金融大数据风控 编辑:程序博客网 时间:2024/05/16 10:22
JAVA replaceAll 正则表达式(持续更新)
Java String类自带了replaceAll 函数,支持正则表达式。
- replaceAll
匹配数字:[0-9]
String tmp = "";String content = "1: In a newly-released report, IEA said it expected oil prices to start picking up in 2017.";tmp = content.replaceAll( "[0-9]{1}" , "china");System.out.println(tmp);tmp = content.replaceAll( "[0-9]{2}" , "china");System.out.println(tmp);tmp = content.replaceAll( "[0-9]{3}" , "china");System.out.println(tmp);tmp = content.replaceAll( "[0-9]{4}" , "china");System.out.println(tmp);tmp = content.replaceAll( "[0-9]+" , "china");System.out.println(tmp);
或用符号的正则表达式
String content = "1: In a newly-released report, IEA said it expected oil prices to start picking up in 2017.";tmp = content.replaceAll( "\\d{1}" , "china");System.out.println(tmp);tmp = content.replaceAll( "\\d{2}" , "china");System.out.println(tmp);tmp = content.replaceAll( "\\d{3}" , "china");System.out.println(tmp);tmp = content.replaceAll( "\\d{4}" , "china");System.out.println(tmp);tmp = content.replaceAll( "\\d+" , "china");System.out.println(tmp);
输出结果:
china: In a newly-released report, IEA said it expected oil prices to start picking up in chinachinachinachina.
1: In a newly-released report, IEA said it expected oil prices to start picking up in chinachina.
1: In a newly-released report, IEA said it expected oil prices to start picking up in china7.
1: In a newly-released report, IEA said it expected oil prices to start picking up in china.
china: In a newly-released report, IEA said it expected oil prices to start picking up in china.
0 0
- JAVA replaceAll 正则表达式(持续更新)
- java正则表达式之replaceAll
- 正则表达式-持续更新
- python 正则表达式 (持续更新)
- java 正则表达式String.replaceAll( "\\s+ ", "| ")
- Java正则表达式 matchs split replaceAll实例
- replaceall 的java正则表达式实现
- String.replaceAll() 正则表达式
- String.replaceall正则表达式
- java 正则 持续更新中
- 最新手机号码正则表达式,持续更新中
- 正则表达式练习,持续更新中
- 正则表达式的应用(持续更新ing)
- 常用正则表达式(持续更新)
- Regex(Regular Expression)正则表达式-----持续更新
- js中的正则表达式,持续更新....
- 常用正则表达式——持续更新
- 常用正则表达式——持续更新
- No such property: GROUP for class: org.gradle.api.publication.maven.internal.deployer
- xen network PV driver 现状分析
- [LeetCode 293] Flip Game
- 随机产生5个从0到10之间不重复的整数
- linux命令大全
- JAVA replaceAll 正则表达式(持续更新)
- handler机制的原理
- python 对纯真数据库操作的代码
- Linux配置自动发送邮件
- Kth number (HDU_2665) 划分树
- ubuntu 安装配置jdk+eclipse+android sdk
- lintcode:Largest Number
- POJ 2349 Arctic Network(Prim)
- linux_shell_HERE Document