2013-05-01 81 views
0

我創建了一個正則表達式匹配這可能是可能的東西串後一個詞匹配像圖所示:正則表達式一個特定的詞

then "hello I am here" blah blah 

then hello blah blah 

我想匹配這個詞剛好在then之後。對於上述字符串的預期輸出

"hello I am here" //if the words are in quotes 

hello 

我想這正則表達式&quot;(\w*[\s]*)*&quot;|(?<=\bthen\s)(\w+),這是工作的罰款在線,但顯示在Firefox錯誤。錯誤

enter image description here

+0

您正在使用回顧後''這是不被JavaScript – 2013-05-01 07:08:11

+0

@ArunPJohny支持,我相信你是指'?<='(如果我刪除了這個,沒有錯誤)。任何其他方式使其工作? – 2013-05-01 07:09:41

+0

請嘗試http://jsfiddle.net/arunpjohny/RVfdr/3/ – 2013-05-01 07:24:28

回答

1

嘗試

var regex = /then\s*(&quot;(.*?)&quot;|(\w*))\s*.*/ 

function getSomething(string){ 
    var arr = regex.exec(string); 
    console.log(arr); 
    return arr.length > 1 ? arr[1] : undefined; 
} 

演示:(?<= ...)Fiddle

+0

謝謝...... :) – 2013-05-01 07:30:43