Jump to content

Matching place holders starting/ending with {{ }}


brick

Recommended Posts

Hi All,

 

I have been haing problems getting a regular expression working to find all matches of the following pattern burried inside XHTML markup inside a variable.

 

{{param1:123_xyz^param2:xyx^param3:123}}

 

I need to match all place holders like the above, including the curly brackets at the start and end.  The params inside can and will vary each and every time and contain mainly alphanumerical characters but also carrats/underscores/colons etc.

 

Could anyone possibly give me some guidance please?

 

Kind regards,

Brick...

 

Is it sufficient to match all {{...}} blocks?

 

If so:

<?php
$sourcestring="{{param1:123_xyz^param2:xyx^param3:123}}";
preg_match_all('/\{\{.*?\}\}/s',$sourcestring,$matches);
echo "<pre>".print_r($matches,true);
?>

$matches Array:
(
    [0] => Array
        (
            [0] => {{param1:123_xyz^param2:xyx^param3:123}}
        )

)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.