javascript/ regex
I have a text and a script
var x = "This is an example url http://www.longurl.com/?a=example@gmail.com&x=y1 and this must me a example url"; function getMatch(str) { var urlRegex = '(?!mailto:)(?:(?:http|https|ftp)://)(?:\\\\S+(?::\\\\S*)?@)?(?:(?:(?:[1-9]\\\\d?|1\\\\d\\\\d|2[01]\\\\d|22[0-3])(?:\\\\.(?:1?\\\\d{1,2}|2[0-4]\\\\d|25[0-5])){2}(?:\\\\.(?:[0-9]\\\\d?|1\\\\d\\\\d|2[0-4]\\\\d|25[0-4]))|(?:(?:[az\\\¡-\\\0-9]+-?)*[az\\\¡-\\\0-9]+)(?:\\\\.(?:[az\\\¡-\\\0-9]+-?)*[az\\\¡-\\\0-9]+)*(?:\\\\.(?:[az\\\¡-\\\]{2,})))|localhost)(?::\\\\d{2,5})?(?:(/|\\\\?|#)[^\\\\s]*)?'; var reg = new RegExp(urlRegex, 'ig'); return str.match(reg); } console.log(getMatch(x));
The expected outcome must be
[ http://www.longurl.com/?a=example@gmail.com&x=y1 ]
but the below getMatch is giving me incorrectly (skipping &x=y1)
http://www.longurl.com/?a=example@gmail.com
How do I modify the function to return a complete URL
NOTE: This happens only when the email arguments are passed after it finds @ character, the function behaves weird.
I have a text and a script
var x = "This is an example url http://www.longurl.com/?a=example@gmail.com&x=y1 and this must me a example url"; function getMatch(str) { var urlRegex = '(?!mailto:)(?:(?:http|https|ftp)://)(?:\\\\S+(?::\\\\S*)?@)?(?:(?:(?:[1-9]\\\\d?|1\\\\d\\\\d|2[01]\\\\d|22[0-3])(?:\\\\.(?:1?\\\\d{1,2}|2[0-4]\\\\d|25[0-5])){2}(?:\\\\.(?:[0-9]\\\\d?|1\\\\d\\\\d|2[0-4]\\\\d|25[0-4]))|(?:(?:[az\\\¡-\\\0-9]+-?)*[az\\\¡-\\\0-9]+)(?:\\\\.(?:[az\\\¡-\\\0-9]+-?)*[az\\\¡-\\\0-9]+)*(?:\\\\.(?:[az\\\¡-\\\]{2,})))|localhost)(?::\\\\d{2,5})?(?:(/|\\\\?|#)[^\\\\s]*)?'; var reg = new RegExp(urlRegex, 'ig'); return str.match(reg); } console.log(getMatch(x));
The expected outcome must be
[ http://www.longurl.com/?a=example@gmail.com&x=y1 ]
but the below getMatch is giving me incorrectly (skipping &x=y1)
http://www.longurl.com/?a=example@gmail.com
How do I modify the function to return a complete URL
NOTE: This happens only when the email arguments are passed after it finds @ character, the function behaves weird.
I have a text and a script
var x = "This is an example url http://www.longurl.com/?a=example@gmail.com&x=y1 and this must me a example url"; function getMatch(str) { var urlRegex = '(?!mailto:)(?:(?:http|https|ftp)://)(?:\\\\S+(?::\\\\S*)?@)?(?:(?:(?:[1-9]\\\\d?|1\\\\d\\\\d|2[01]\\\\d|22[0-3])(?:\\\\.(?:1?\\\\d{1,2}|2[0-4]\\\\d|25[0-5])){2}(?:\\\\.(?:[0-9]\\\\d?|1\\\\d\\\\d|2[0-4]\\\\d|25[0-4]))|(?:(?:[az\\\¡-\\\0-9]+-?)*[az\\\¡-\\\0-9]+)(?:\\\\.(?:[az\\\¡-\\\0-9]+-?)*[az\\\¡-\\\0-9]+)*(?:\\\\.(?:[az\\\¡-\\\]{2,})))|localhost)(?::\\\\d{2,5})?(?:(/|\\\\?|#)[^\\\\s]*)?'; var reg = new RegExp(urlRegex, 'ig'); return str.match(reg); } console.log(getMatch(x));
The expected outcome must be
[ http://www.longurl.com/?a=example@gmail.com&x=y1 ]
but the below getMatch is giving me incorrectly (skipping &x=y1)
http://www.longurl.com/?a=example@gmail.com
How do I modify the function to return a complete URL
NOTE: This happens only when the email arguments are passed after it finds @ character, the function behaves weird.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.