简体   繁体   中英

Match only “www.example.com” but not “www. some text”

Need regex to match links like www.example.com in an html/text -string but:

  • not match "www. some text after"
  • not match "www" only such as "some text before www some text after"
  • not match link with http
  • must start with white space ( \\s ) or not character before such as: " www.example.com" or "www.example.com"

I tried with:

'/(^|\s)(www[^\s].[^<> \n\r \s]+)/iex'

but also match "www. some text after"

You were looking for

/(^|\s)(www[^<>\s]+)/

\\s includes \\n , \\r


You can also use (?<=^|\\s)(www\\.[^<>\\s.]+\\.[^<>\\s.]+)(?=\\s|$)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM