4

正規表現を使用して、文字列が特定のキーワードと等しいかどうかを確認できます。次に例を示します。

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

ありがとう!

4

2 に答える 2

1

^(?!hello$)(ドロップ.*)

(...後読み/先読みの混乱を修正)

于 2012-05-23T08:07:05.887 に答える