1

Pattern:

#(?<!\img])(((http|ftp|https):\/\/)|a-z0-9.\-|www\.)[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#!]*[\w\-\@?^=%&/~\+#])?#i

As you can see I got the right modifiers - not like in the other questions. However its still not working giving the error:

preg_replace_callback(): Unknown modifier '!' in [..]

Whats the problem? I am out of the ideas. I'd appreciate any kind of help.

Cyclone
  • 14,839
  • 23
  • 82
  • 114

1 Answers1

2

It's because you have this bit in the middle:

([\w\-\.,@?^=%&:/~\+#!]*

You're using # as the delimiter, so the regex engine reckons that the # in that section is the ending delimiter of the regex. It therefore presumes that the ! is an attempt at a modifier, and then gets confused when it is an invalid modifier. You need to escape the #:

([\w\-\.,@?^=%&:/~\+\#!]*

Edit

Exactly the same thing happens in the following section:

[\w\-\@?^=%&/~\+#]

should be

[\w\-\@?^=%&/~\+\#]

for exactly the same reasons.

lonesomeday
  • 233,373
  • 50
  • 316
  • 318