Regex doesn't work in String.matches()

前端 未结 9 1193
余生分开走
余生分开走 2020-11-22 13:21

I have this small piece of code

String[] words = {\"{apf\",\"hum_\",\"dkoe\",\"12f\"};
for(String s:words)
{
    if(s.matches(\"[a-z]\"))
    {
        Syste         


        
9条回答
  •  我在风中等你
    2020-11-22 13:36

    java's implementation of regexes try to match the whole string

    that's different from perl regexes, which try to find a matching part

    if you want to find a string with nothing but lower case characters, use the pattern [a-z]+

    if you want to find a string containing at least one lower case character, use the pattern .*[a-z].*

提交回复
热议问题