2012-07-26 68 views
0

我這究竟具體要求,Regex split string preserving quotes正則表達式分割字符串保存報價在JavaScript

但在JavaScript中。

研究圖書館 「不可用」 的作者: 「蕭伯納」

研究

「不可用」

筆者: 「蕭伯納」

I gues s js不支持積極lookbehind(谷歌搜索:) :))。我無法在js中乾淨地做到這一點。 任何幫助將非常好,因爲我不太瞭解正則表達式。

在此先感謝。

+0

請參考以下鏈接: http://stackoverflow.com/questions/2817646/javascript-split-string-on-space-或在報價到數組 – 2012-07-26 06:37:21

+0

我試過了,但它不符合要求。 – user1427553 2012-07-26 06:45:55

回答

0

爲我工作。可能是你錯過了一些東西。

我嘗試下面的代碼,它工作得很好:

<html> 
<script type="text/javascript"> 
    var str = 'single words "fixed string of words"'; 
    var split_str = str.match(/\w+|"[^"]+"/g) 
    alert(split_str[0]); 
    alert(split_str[1]); 
    alert(split_str[2]); 
</script> 
</html> 
+0

我只是爲研究圖書館「不可用」作者測試:「Bernard Shaw」(有問題提及)及其期望的o/p - 根據需要。 – user1427553 2012-07-26 07:10:41

+0

你嘗試過使用問題中提到的字符串嗎? – 2012-07-26 07:11:58

+0

是的,我做到了。但我的要求正如問題中提到的那樣。 – user1427553 2012-07-26 07:18:50

相關問題