apple-juice
パラメータに従って一致する必要があることに気付きましたが、どうapple juice
ですか? 検証している場合apple juice
でも、失敗したいと思っていると思います。
それでは、「境界」としてカウントされる一連の文字を作成しましょう。
/[^-a-z0-9A-Z_]/ // Will match any character that is <NOT> - _ or
// between a-z 0-9 A-Z
/(?:^|[^-a-z0-9A-Z_])/ // Matches the beginning of the string, or one of those
// non-word characters.
/(?:[^-a-z0-9A-Z_]|$)/ // Matches a non-word or the end of string
/(?:^|[^-a-z0-9A-Z_])(apple|orange|juice)(?:[^-a-z0-9A-Z_]|$)/
// This should >match< apple/orange/juice ONLY when not preceded/followed by another
// 'non-word' character just negate the result of the test to obtain your desired
// result.
ほとんどの正規表現フレーバー\b
では、「単語境界」としてカウントされますが、「単語文字」の標準リストには含まれない-
ため、カスタムのものを作成する必要があります。/\b(apple|orange|juice)\b/
あなたもキャッチしようとしていなければ、それは一致する可能性が-
あります...
「単一単語」テストのみをテストしている場合は、はるかに単純なテストを使用できます。
/^(apple|orange|juice)$/ // and take the negation of this...