当前页面: 开发资料首页 → J2SE 专题 → 请问如何用正则表达式判断一个字符串是否含有一个特定的子字符串
请问如何用正则表达式判断一个字符串是否含有一个特定的子字符串
摘要: 请问如何用正则表达式判断一个字符串是否含有一个特定的子字符串
比如字符串为“This is, a Hello world, test!”
用什么样的正则表达式可以判断是否含有“Hello”子字符串呢?多谢了
没有用过,刚学习了一下
/sHello/s
String str="This is, a Hello world, test!";
System.out.println(str.indexOF("Hello"));
(?<=(?s).*?)Hello(?=(?s).*?)
String h=".*Hello.*";
Pattern p=Pattern.compile(h);
Matcher m=p.matcher("This is, a Hello world, test!”);
System.out.println(m.find());
学习!