字符串应符合要求:
1.由一些用空格分隔的单词组成。
2.只允许每个单词中的字母,数字,下划线,'和'
3.每个单词必须以字母或引号开头
现在我写了这个并且它不符合最后的要求:
public boolean test(String string) {
return string.matches("[A-Za-z0-9_' \"]+");
}
如果我给出一个非法的字符串“这个世界以123digit开头”,它将返回false,但它返回true:
public boolean test("there is a word start with 123digit"){
\\my previous code return true.
\\so someone PLEASE HELP to implement the method so
\\ it will return false in such situation.
}
也是这种情况,它应该返回false:
public boolean test("there is a word start with _underscore"){
\\my previous code return true.
\\so someone PLEASE HELP to implement the method so
\\ it will return false in such situation.
}