我有一個非常漂亮的工具,underscore-cli,打印出幫助/用法信息時是越來越奇怪的行爲。在匹配行首時,JavaScript V8正則表達式引擎中的錯誤?
在使用()函數,我這樣做是爲了文本縮進塊(例如,選項):
str.replace(/^/, " ");
此正則表達式,除了是很明顯的,當屬直出的TJ Hollowaychuk的碼。正則表達式是正確的。
然而,我得到插進我的使用文本中間空間的bizzare。像這樣:
Commands: ... values Retrieve all the values of an object's properties. extend <object> Override properties in the input data. defaults <object> Fill in missing properties in the input data. any <exp> Return 'true' if any of the values in the input make the expression true. Expression args: (value, key, list) all <exp> Return 'true' if all values in the input make the expression true. Expression args: (value, key, list) isObject Return 'true' if the input data is an object with named properties isArray Return 'true' if the input data is an array isString Return 'true' if the input data is a string ...
99%的機會,這已經是在V8中的錯誤。
任何人都知道爲什麼會這樣,還是最簡單的變通辦法會是什麼?
是的,結果是這個IS一個V8的錯誤,1748是確切的。下面是the workaround I used in the tool:
str.replace(/(^|\n), "$1 ");
只需在開頭添加一個字符串? – 2012-04-14 01:06:53
你有沒有清理回車的文字? – Trey 2012-04-14 01:13:26
你有沒有試過把空間以外的東西?瀏覽器不設於顯示多個空間 - 爲了把你需要使用' '... – 2012-04-14 01:18:59