java代码如何检测字符串是否包含一个字母呢?
下文笔者讲述使用java代码检测字符串至少包含一个字母的方法分享,如下所示
实现思路:
使用正则表达式".*[a-zA-Z]+.*"
例:检测字符串中是否包含一个字母的示例分享
/**
* java265.com 字符串是否包含字母的示例
*
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String str = "java265.com";
String regex=".*[a-zA-Z]+.*";
Matcher m=Pattern.compile(regex).matcher(str);
System.out.println("flag:" + m.find());
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


