0

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"

KingCrunch
  • 128,817
  • 21
  • 151
  • 173
Branislav
  • 315
  • 1
  • 3
  • 13

1 Answers1

1

You were looking for

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

\s includes \n,\r


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

Anirudha
  • 32,393
  • 7
  • 68
  • 89