Regex doesn't work in String.matches()

前端 未结 9 1151
余生分开走
余生分开走 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

    I have faced the same problem once:

    Pattern ptr = Pattern.compile("^[a-zA-Z][\\']?[a-zA-Z\\s]+$");
    

    The above failed!

    Pattern ptr = Pattern.compile("(^[a-zA-Z][\\']?[a-zA-Z\\s]+$)");
    

    The above worked with pattern within ( and ).

提交回复
热议问题