下面的正则表达式是错误的 - 有人可以帮助找到所有:-)没有“请忽略我”在前面? 我以前没有需要这样的正则表达式。词边界可能会混淆事物。
感谢Negative look-around
<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>
看看这个http://stackoverflow.com/questions/2973436/regex-lookahead-lookbehind-and-atomic-groups/2973609#2973609 – Amarghosh 2010-07-20 09:34:43