Skip to content
Advertisement

preg_match bbcode

I currently have bbcode like this

image.jpg

I’d like to use php’s preg_match so I can get the value of the image.jpg, regardless of what’s next to ‘caption=’. Can someone help me out?

Advertisement

Answer

Raw regex:

]([^]]+)[/caption]

preg_match("]([^]]+)[/caption]", myString, $matches)

image.jpg would be in the first group. $matches[1] (I’m not certain I escaped it correctly in php).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement