如何用正则表达式匹配字符串中的第一个字符? [英] How to match the first character in a String with a regexp?

查看:1558
本文介绍了如何用正则表达式匹配字符串中的第一个字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个正则表达式来评估单词的第一个字符是否是小写字母。

I need a regular expression to evaluate if the first character of a word is a lowercase letter or not.

我有以下Java代码: Character.toString(charcter).matches( [az?])

I have this java code: Character.toString(charcter).matches("[a-z?]")

例如,如果我有这些单词,结果将是:

For example if I have those words the result would be:


  • a13 => true

  • B54 => false

  • & 32 => false

我只想匹配一个字母,不知道是否需要使用?,。或 [az]之后或之内的 {1}

I want to match only one letter and I don't know if I need to use "?", "." or "{1}" after or inside "[a-z]"

推荐答案

有一种内置方法,无需正则表达式

There is a built in way to do this without regexes.

Character.isLowerCase(string.charAt(0))

这篇关于如何用正则表达式匹配字符串中的第一个字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆