tags:

views:

20

answers:

1

I'm trying to match tags using preg_replace. The regex used is: <video[^>]*>(.*?)</video>

But I'm getting a server warning: Message: preg_replace() [function.preg-replace]: Unknown modifier ']'

Any clues on why?

Also, How could I modify the regex so it can match [video] tags instead?

Thanks!

+1  A: 

Don't forget to delimit your regex, as required in the preg_ functions. Usually we would write /regex/, but any delimiters will do.

Since your regex contains /, I'll go for %, to avoid escaping it.

%<video[^>]*>(.*?)</video>%

Of course, watch out for the perils of trying to mess with HTML via regex. There will be issues. As always.

If you want [video] instead, just replace all <> with [] - but remember to escape them, since [ and ] are significant in regular expressions!

%\[video[^\]]*\](.*?)\[/video\]%
Matchu
Thanks a billion! About the html.. I know, but it's just a quick replace for video code. Shouldn't be too problematic.
ign
@Ignacio - glad to help :) I'm sure you know, but please remember to click the check mark next to the answer once SO will let you :D Thanks!
Matchu