0

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\])?)(\]?)/';
1
  • What is your question? Commented Nov 15, 2013 at 3:39

1 Answer 1

1

I think you're overthinking it a bit

preg_match_all('/\[lightbox link="(.*?)".*\]/i', $str, $matches);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.