-7

文字列は次の要件を満たす必要があります。

1.スペースで区切られたいくつかの単語で構成されています。

2. 各単語には、文字、数字、アンダースコア、' および " のみを使用できます

3.各単語は文字または引用符で始まる必要があります

今、私はこれを書きましたが、最後の要件を満たしていません:

public boolean test(String string) {
return string.matches("[A-Za-z0-9_' \"]+");
}

不正な文字列 "this world start with 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.
}
4

1 に答える 1