Regx for a domain with or without www

I want to find the domain name from the given string.

Lorem www.example.in ipsum # web developer dolor sit amet, consectetur adipiscing elit. Donec suraj@mishra.com , therefore, sem eros, et volutpat google.com lacus dignissim ac. Pellentesque ac nisl et erat porta feugiat. + 91-141-2561894 Vestibulum #web_designing sodales semper stackoverflow.com

what i tried

(www.)?[^@]\w+\.+\w{2,3}

return it to me 5 matches   www.exa mple.in mishra.com google.com stackoverflow.com where I need only 3 bold matches.

Can you guys help me find out what I'm doing wrong?

Here is the RegEx101 Test

console.log("Lorem www.example.in ipsum #web-developer dolor sit amet, consectetur adipiscing elit. Donec suraj@mishra.com consequat sem eros, et volutpat google.com lacus dignissim ac. Pellentesque ac nisl et erat porta feugiat. +91-141-2561894 Vestibulum #web_designing sodales semper stackoverflow.com".match(/(www.)?[^@]\w+\.+\w{2,3}/g))
Run codeHide result
+4
1

( PCRE):

\b(?<!@)(?:www\.)?[^@\s]+\.\w{2,3}
  • \b(?<!@) - , ...@mishra.com

https://regex101.com/r/knOchH/5

+2

Source: https://habr.com/ru/post/1689111/


All Articles