0
votes

I've been finding url from text by preg_match with this pattern /(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/

Any further solutions for detecting domains instead of url? May be with a list of top-level domain like this: .asia .biz .cat .com .net .edu .gov .info .com.eu .com.au

//Edit

For example I have a paragraph like this:

Hello world. https://stackoverflow.com/posts/22112284/edit

And I want to find this domain stackoverflow.com in that text.

1
TLDs may have much more than 3 characters, see: iana.org/domains/root/dbToto

1 Answers

1
votes

If you just want the domain, then just stop at a slash. In fact, you've got it there already, just shorten it. I also added another spot the the end, as there are some wierd top level domains out there (.info, .mobi for instance)

(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}