Java使用正则表达式判断字符串中是否包含某子字符串
需求:
给定一个字符串s,判断当s中包含“tree fiddy"或“3.50”或“three thirty”子字符串返回true,否则返回false.
题目来自代码勇士。
import java.util.regex.Pattern;
/** * 判断字符串中是否包含某字符串 * * @author dylan * @create 2017-12-14 **/ public class Nessie { public static boolean isLockNessMonster(String s) { return Pattern.matches(".*(tree fiddy|3\.50|three fifty).*", s); } public static void main(String[] args) { System.out.println(isLockNessMonster("tree fiddy123")); } }
输出:
true
声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: linux 查看磁盘空间占用情况
- 下一篇: ubuntu下crontab 定时执行php脚本