Jump to content

Simple RegEx problem...


Joshua4550

Recommended Posts

As far as I can tell the only things at fault with the OPs original post was the attempting to use str_replace (which doesn't support REGEX patterns) rather than preg_replace. And the fact that with preg_replace the pattern would require delimiters. Assuming the input could contain more than one quote block however you will also need to make the section between the

tags lazy (which I've done with the question mark). Also making the first catch all match lazy or changing it is required (I replaced it with 'one or more character(s) not ]).

 

$pattern = '#\[quote[^]]*\].*?\[/quote\]#';
$output = preg_replace($pattern, '', $input);

Probably because your input has newline characters between the

and

tags. By default the . does not match newline characters, if you need it to do so then add the s modifier, you may also wish to add the i modifier to make it case-insensitive, so that

will also match.

 

$pattern = '#\[quote[^]]*\].*?\[/quote\]#is';
$output = preg_replace($pattern, '', $input);

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.