我有这样的正则表达式:
string.match(/((?:website.com\/video\/)([\d]+))/);
当字符串匹配时,一切都很好,但是它总是会返回某些东西,即使字符串是" facebook.com",我仍然会回来&#34 ; facebook.com",如何让它返回null?
答案 0 :(得分:1)
这应该可以正常工作,但是字符串是immutable所以我猜你没有返回结果,只是期望原始字符串改变:
string = string.match(/((?:website.com\/video\/)([\d]+))/);
如果不匹配,将返回null
。
答案 1 :(得分:0)
可能晚了,但这是我的50c
(function ($) {
$(document).ready(function () {
// var string = 'website.com/video/1'; // uncomment to test
var string = 'facebook.com';
if (string.match(/((?:website.com\/video\/)([\d]+))/)) {
$("p").html(string);
} else {
$("p").html("No match");
}
});
})(jQuery);