java正则表达式可算知道些了
来源:互联网 发布:centos 压缩文件 编辑:程序博客网 时间:2024/06/01 19:15
import static net.mindview.util.Print.*;
import java.util.regex.*;
public class TestRegularExpress
{
public static void main(String[] args)
{
String s = "a88897a";
print(s.matches("..."));
print(s);
print(s.replaceAll("//d", "-"));
print();
print(" /r/n/t".matches("//s{4}"));
print("".matches("//S"));
print("a_8".matches("//w{3}"));
print("abc888&^%".matches("[a-z]{1,3}//d+[&^%#]+"));
print("//".matches("////"));
print("192.168.25.8".matches("//d+//.//d+//.+//d.+//d+"));
print();
print("a".matches("[abc]"));
print("a".matches("[^abc]"));
print("A".matches("[a-zA-Z]"));
print("A".matches("[a-z]|[A-Z]"));
print("A".matches("[a-z[A-Z]]"));
print("R".matches("[A-Z[RFJ]]"));
print();
print("a".matches("//p{Lower}"));
print();
print("hello sir".matches("^h.*"));
print("hello sir".matches(".*ir$"));
print("hello sir".matches("^h[a-z]{1,3}0//b.*"));
print("hello sir".matches("^h[a-z]{1,3}0//b.*"));
print(" /n".matches("^[//s&&^//n]*//n$"));
print();
Pattern p = Pattern.compile("//d{3,5}");
s = "123-34345-234-00";
Matcher m = p.matcher(s);
print(m.matches());
m.reset();
print(m.find());
print(m.start() + "-" + m.end());
print(m.find());
print(m.start() + "-" + m.end());
print(m.find());
print(m.start() + "-" + m.end());
print(m.find());
print();
print(m.lookingAt());
print(m.lookingAt());
print(m.lookingAt());
print(m.lookingAt());
print();
print("aagdsgdsgds@sgdgds.com".matches("[//w[.-]]+@[//w[.-]]+//.[//w]+"));
Pattern pp = Pattern.compile("java",Pattern.CASE_INSENSITIVE);
Matcher mm = pp.matcher("java Java JaVa JAVa JAva Ilove Java abadfefwee");
//print(mm.replaceAll("JAVA")); //java全被换为JAVA
StringBuffer buffer = new StringBuffer();
int i = 0;
while(mm.find())
{
i++;
if(i%2==0)
mm.appendReplacement(buffer, "java");
else
mm.appendReplacement(buffer, "JAVA");
}
mm.appendTail(buffer);
print(buffer);
print();
pp = Pattern.compile("(//d{3})([a-z]{2})");
s = "123aa-354bb-454cc-00";
m = pp.matcher(s);
while(m.find())
{
print(m.group(1));
print(m.group(2));
print(m.group());
}
print();
s = "aaaa5bbbb6";
pp = Pattern.compile("(.{3,10}+)[0-9]");
m = pp.matcher(s);
if(m.find())
print(m.start() + "---" + m.end());
else
print("not match");
}
}
- java正则表达式可算知道些了
- 正则表达式 Java(来自百度知道)
- 你应该知道的10个Java正则表达式
- 你应该知道的10种java正则表达式
- 慢慢收集java正则表达式,以后可能用得到
- c#可中正则表达式
- Java 正则表达式正则
- 【正则表达式】Java正则表达式
- 正则表达式 JAVA正则表达式
- 【Java】【正则表达式】正则表达式
- 今天玩了一下JAVA的正则表达式
- javascript 正则表达式基础(要知道)
- 十个应该知道的正则表达式例子
- 我所知道的正则表达式
- 十个你需要知道的正则表达式
- 十个应该知道的正则表达式例子
- 必须知道的20个正则表达式
- 你不知道的正则表达式
- Oracle 中常见函数在teradata中如何实现
- 等咱有了钱......(全集)
- Java程序员,面试必读
- (5)ubuntu8访问windows共享目录2——加载mount
- 下载delphi 5 至 delphi 2010
- java正则表达式可算知道些了
- 欢迎来
- Hash之MD5、SHA1、CRC
- 蔡明介:不介意被称为“山寨之父”
- 2009/08/02
- MTD(memory technology device内存技术设备)
- 软件测试过程质量的度量
- Linux之父回应微软开源Linux代码
- GridView系列(一)排序列头加箭头