1

次の正規表現は間違っています - 誰かがすべてを見つけるのを手伝ってくれませんか? 私は以前にそのような正規表現を必要としませんでした。境界という言葉は物事を混乱させるかもしれません。
ありがとう

<script type="text/javascript">
function regexTest(string, assert) {
  document.write('<hr>')
  document.write(string)
  document.write("[")
  document.write(string.match(/\b((?!please ignore me )\:\-\))\b/gi)!=null);
  document.write("]?" + assert);
}

regexTest("1. this is the first string :-)        ",true);
regexTest("2. :-)",true)
regexTest("3. another string:-)here",true);
regexTest("4. Ending a sentence with :-)",true);
regexTest("5. please ignore me :-)",false);
</script>
4

1 に答える 1

9

「Please ignore me」が前に付い:-)ていないa と一致させたい場合は、 lookaheadの代わりに否定の後読みが必要になります。ただし、JavaScript は後読みをサポートしていません。(?<!...)(?!...)

したがって、(\bplease ignore me\s*)?:-\)一致する場合は、キャプチャ グループ$1が空かどうかを確認することができます。

于 2010-07-20T09:20:21.367 に答える