站内搜索: 请输入搜索关键词

当前页面: 开发资料首页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());


学习!


↑返回目录
前一篇: 散分~~~``咨询今后发展和培训推荐~`````````
后一篇: 科学计数法5,123.89 如何格式化回5123。89(除了用replace外)?