Search code examples
phpregexplaceholder

Replace text double-wrapped in square braces with new text


this probably will be fairly simple, but how am I able to find all the matches using regex of this occurrence in a load of text.

[[data in here]]

EG:

Blah blah blah [[find]] and maybe [[this]]

So I am able to find the occurrences and then replace them as urls.

Does that make sense?

I tried using

preg_match_all("/[[([^<]*)]]/", $data, $matches, PREG_OFFSET_CAPTURE);

But returns errors.


Solution

  • Try this:

    preg_match_all("/\[\[(.+?)\]\]/", $data, $matches, PREG_OFFSET_CAPTURE);