how to not include punctuation after url

Multi tool use
how to not include punctuation after url
So I have this code,
const urlPattern1 = new RegExp(
"(https?://(?:www.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9].[^s]{2,}[^.,!?:;s]+$/?|www.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9].[^s]{2,}[^.,!?:;s]+$/?|https?://(?:www.|(?!www))[a-zA-Z0-9].[^s]{2,}|www.[a-zA-Z0-9].[^s]{2,}[^.,!?:;s]+$/?)"
)
I would like it to not include any punctuation after the URL. So right now if I type in "www.google.com/..." then it will correctly only register the "www.google.com/". However, if I type in "www.google.com.!" then I want it to still only register "www.google.com", but right now it registers nothing. It seems like it is only processing the periods correctly, and any other punctuation (like !) is not getting processed correctly. Any help?
www.google.com
http
https
1 Answer
1
(?:http(?:s)?://)?(www.[^.]+.w+)
(?:http(?:s)?://)?(www.[^.]+.w+)
Try that. Go to https://regexr.com and put
www.google.com
www.google.com/...
www.google.com.!
http://www.google.co-!#{}
as the test string, and put that as the regex. It should work.
www.google.com // Matches www.google.com
www.google.com/... // Matches www.google.com
www.google.com.! // Matches www.google.com
http://www.google.co-!#{} // Matches www.google.co
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I’m trying your regex at regex101 and the only thing it seems to match is
www.google.com
alone, which makes sense since only the third of the four choices you provide is not anchored to the end of the input, and that one is for URLs beginning withhttp
/https
.– Aankhen
Jul 2 at 23:54