Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to regex all lightbox wordpress shortcodes and receive their 'link' attribute.

Example:

[lightbox link="http://www.test.com/photo1.jpg" width="150" align="none" title="photo 1" frame="true" icon="image"]
[lightbox link="http://www.test.com/photo2.jpg" width="150" align="none" title="photo 2" frame="true" icon="image"]
...
[lightbox link="http://www.test.com/photo5.jpg" width="150" align="none" title="photo 5" frame="true" icon="image"]

There can be any number of these shortcodes but I need to get all their link attributes:

http://www.test.com/photo1.jpg

My pattern I am working with:

$pattern = '/\[(\[?)(lightbox)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)/';
share|improve this question
    
What is your question? –  iMat Nov 15 '13 at 3:39

1 Answer 1

I think you're overthinking it a bit

preg_match_all('/\[lightbox link="(.*?)".*\]/i', $str, $matches);
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.