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.

Related Question Regular Expression to find URLs in block of Text (Javascript) Extracting 1 or more hyperlinks from paragraph text in Javascript using Regular Expression How to extract text using Regular expression (RegEx)? Remove Breaks from start and end of the paragraph using Regular expression Extract text in Regular Expression in Javascript Extract text of paragraph using nextSibling Extract inner text from anchor tag string using a regular expression in JavaScript Regular expression to extract text from a string in html format Extract data using regular expression How to extract block comments from a string using regular expressions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM