0

需要正则表达式来匹配-string中www.example.com的链接,但是:html/text

  • 不匹配"www. some text after"
  • 不匹配"www" only such as "some text before www some text after"
  • 与链接不匹配http
  • 必须以空格 ( \s) 或非字符开头,例如:" www.example.com""www.example.com"

我试过:

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

但也匹配"www. some text after"

4

1 回答 1

1

你在寻找

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

\s包括\n,\r


你也可以使用(?<=^|\s)(www\.[^<>\s.]+\.[^<>\s.]+)(?=\s|$)

于 2013-01-14T11:17:36.830 回答