正規表現を使用して、文字列が特定のキーワードと等しいかどうかを確認できます。次に例を示します。
Regex: /^hello$/
String: hello
Result: matches, as expected
Regex: /^goodbye$/
String: goodbye
Result: matches, as expected
Regex: /^bye$/
String: bye bye
Result: does not match, as expected
私が達成できないのは、文字列がキーワードと等しくないかどうかを確認することです。ここに私がやろうとしていることのいくつかの例があります:
Regex: ^(?!hello).*$
String: bye
Result: matches, as expected
Regex: ^(?!hello).*$
String: bye bye
Result: matches, as expected
Regex: ^(?!hello).*$
String: say hello
Result: matches, as expected
Regex: ^(?!hello).*$
String: hello you
Result: does not match, but should match because "hello you" is not equal to "hello"
私は近くにいると思います^(?!hello).*$
が、これについては手が必要です。別の例を次に示します。
Regex: ^(?!fresh\sfruits).*$
String: fresh fruits
Result: does not match, as expected
Regex: ^(?!fresh\sfruits).*$
String: lots of fresh fruits
Result: matches, as expected
Regex: ^(?!fresh\sfruits).*$
String: fresh fruits, love them.
Result: does not match, but should match
ありがとう!