JavaScript:好的部分;为什么提前行不好? [英] JavaScript: The Good Parts; why is lookahead not good?
问题描述
我正在阅读Douglas Crockfords JavaScript:好的部分,我刚刚完成了正则表达式一章.在本章中,他称JavaScript的\b
,正向超前(?=)
和负向超前(?!)
不是很好的部分"
I'm reading Douglas Crockfords Javascript: The Good Parts, I just finished the regular expressions chapter. In this chapter he calls JavaScript's \b
, positive lookahead (?=)
and negative lookahead (?!)
"not a good part"
他解释了\b
不好的原因(它使用\w
进行单词边界查找,而\w
对于使用Unicode字符的任何语言都失败),这对我来说似乎是一个很好的理由.
He explains the reason for \b
being not good (it uses \w
for word boundary finding, and \w
fails for any language that uses unicode characters), and that looks like a very good reason to me.
不幸的是,忽略了正面和负面的前瞻性不好的原因,我无法提出一个理由. 掌握正则表达式向我展示了它的强大功能前瞻性(当然会解释它带来的问题),但是我真的想不出任何可以将其视为不好的部分"的东西.
Unfortunately, the reason for positive and negative lookahead being not good is left out, and I cannot come up with one. Mastering Regular Expressions showed me the power that comes with lookahead (and of course explains the issues it brings with it), but I can't really think of anything that would qualify it as "not a good part".
任何人都可以解释为什么通常认为JavaScript(正|负)前瞻或(正|负)前瞻吗?
It seems I'm not the only one with this question: one and two.
推荐答案
Maybe it's because of Internet Explorer's perpetually buggy implementation of lookaheads. For anyone authoring a book about JavaScript, any feature that doesn't work in IE might as well not exist.
这篇关于JavaScript:好的部分;为什么提前行不好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!