Forum Moderators: coopster
What I'm looking to do with my regex pattern is to convert:
[[Link]] => Link
[[Complex link¦Link]] => Link
[[A more complex link!¦Link]] => Link
[[Link]]s => Links
[[File:Image.jpg¦thumb¦An example with a [[link]]]] => [[File:Image.jpg¦thumb¦An example with a link]]
[[Image:Image.jpg¦thumb¦An example with a [[link]]]] => [[Image:Image.jpg¦thumb¦An example with a link]]
And do nothing to:
[[File:Image.jpg¦thumb]]
[[Category:Examples]]
[[fr:Le link]]
[[be-x-old:Linko]]
What I have is:
$contents=$input;
$contents=preg_replace("/\[\[[a-z]{2,7}:[^\¦\.]+\]\]/iU","",$contents);
$contents=preg_replace("/\[\[[^:\¦]+\¦([^:\{\}\¦]+)\]\][^\[\]]/i","$1",$contents);
$contents=preg_replace("/\[\[([^:]+)\]\]/iU","$1",$contents);
$output=$contents;
And while it does an ok job, I'm noticing its a little loosely written, and sometimes takes out large chunks of code, leaves behind random brackets, and takes out spaces between words.
Any help is greatly appreciated.