2015-07-20 46 views

回答

2

你可以使用这个表达式:

/file="([^"]+)/ 

,抢捕获组#1

代码:

var fval = (str.match(/file="([^"]+)/) || ['', ''])[1]; 
+1

有趣的是,我看到你的逻辑,通过抓住了双引号之间有什么。我原本是想要一个更复杂的方法。 – coffeemonitor

+0

如果解决了,您可以将答案标记为已接受。 – anubhava

2

var text = '<!-- #include file="inc/funcs.asp" -->'; 
 
var str = text.match(/"(.*?)"/); 
 
alert(str[1]);

0
var str = '<!-- #include file="inc/funcs.asp" -->'; 
str.match(/\"(.+)\"/)[1]; 

返回 “INC/funcs.asp”