|
Posted by Ian Taylor on 02/23/06 23:24
Jake wrote:
> I am trying to write a regular expression that will strip out wikicode
> links. The links can be in the following two formats.
>
> [[xxx]] or [[yyy|xxx]]
>
> I want to display "xxx" in all cases. This is the closest that I have
> come up with
>
> $text = ereg_replace ("\[\[([^|\]]*\|)?([^\]]*)\]\]", "\\2",$text);
This seems to work for me (using preg_replace instead of ereg_replace,
which uses the Perl regex engine, and is faster IIRC):
echo preg_replace("/\[\[.*?\|?([^\|\]]*)?\]\]/" ,"\\1", $text1);
HTH,
Ian.
Navigation:
[Reply to this message]
|