下面的正則表達式是錯誤的 - 有人可以幫助找到所有:-)沒有「請忽略我」在前面? 我以前沒有需要這樣的正則表達式。詞邊界可能會混淆事物。
感謝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