需求:
给定一个字符串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
本文介绍了一个字符串匹配的问题案例,通过使用正则表达式的方法来检查一个字符串中是否包含特定的子字符串,例如“treefiddy”、“3.50”或“threefifty”。通过Java实现并提供了一个具体的例子。
1273

被折叠的 条评论
为什么被折叠?



