我有一个字符串:
function test(){
var datas = "http://localhost/test/test.html?src=www.123@gmail.com(testing)";
var spl = datas.match(/[^src=]?\b*/g);
document.getElementById('demo').innerHTML = spl;
}
test();
<p id="demo"></p>
我需要src=
字符串匹配后的整个字符串。我需要一个像www.123@gmail.com(testing)
这样的答案。请帮助我.. .更正我的代码
最佳答案
这是一种方法。您肯定需要查找一些有关使用正则表达式的在线教程。
var datas = "http://localhost/test/test.html?src=www.123@gmail.com(testing)";
var m1 = datas.match(/[&?]src=([^&]+)/);
var spl = "notfound";
if (m1 && m1.length>1) spl=m1[1];
document.getElementById('demo').innerHTML = spl;
关于javascript - 在匹配单词后使用正则表达式获取字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38932206/