2013-05-01 84 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