0
[div="desc"][1="text1"][2="text2"][3="link3"][/div]

And it continue could continue to a limit of 6. How could create a regex that extract the "desc", the numbers and the texts? I tried with php array, but i wasn't able.

Thank you!

1
  • 1
    Where is recursion in this? and will the format be the same for all subsequent texts? Commented May 13, 2012 at 13:43

1 Answer 1

2

There is no recursion here - at least your example doesn't show it. If there does turn out to be recursion in your general case, regexes won't work; you will have to use a parser.

For this case, I would suggest first using preg_match_all with a regex like /[([^]]+)]/ . If you pass an array matches to this function, after running preg_match_all, matches[1] should be an array containing the strings '[div="desc"]', '[1="text1"]', etc. Once you have this array, you can loop through it using foreach and split each string on = and then do whatever you like with the two parts of the string that you parsed.

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.