我在最近2个小时内坚持这件事,为什么第一个正则表达式工作而不是第二个?为什么两个正则表达式都不在for循环中?
谢谢!
var urlRegex = /((http|https):\/\/)?((?:(?:[a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF_-]+\.)+))?((([a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF_-][0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF-_]?[a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF_-]?[0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF-_]?)|([a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF_-]{4,1000}))\.(?:([a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{3,3}\.[a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)|([a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF_-]+)))([a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF_.,@?^=%&:/~+#-]*[a-zA-Z0-9\u00C0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF@?^=%&~+#-])?/g;
var updatedData = { websiteUrl:
[ 'http://www.kdjyufghsuidt.ca/ghsuidt_fr.html',
'http://dasjhdjha.kl' ] };
var iRegex;
var queryArray = [];
for (var i = 0; i< updatedData.websiteUrl.length; i++) {
queryArray.push(urlRegex.exec(updatedData.websiteUrl[i]));
}
console.log("queryArray at [1] should be a valid array, but instead it's null: " + JSON.stringify(queryArray[1]));
console.log("queryArray at [0] is working normally: " + JSON.stringify(queryArray[0]));