我有一个像这样的正则表达式:
string.match(/((?:website.com\/video\/)([\d]+))/);
当字符串应该匹配时,一切都很好,但是即使字符串是“facebook.com”,它总是返回一些东西,我仍然返回“facebook.com”,我怎样才能让它返回 null?
我有一个像这样的正则表达式:
string.match(/((?:website.com\/video\/)([\d]+))/);
当字符串应该匹配时,一切都很好,但是即使字符串是“facebook.com”,它总是返回一些东西,我仍然返回“facebook.com”,我怎样才能让它返回 null?
可能晚了,但这是我的 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);