You are here: Re: Regular Expression help « PHP Programming Language « IT news, forums, messages
Re: Regular Expression help

Posted by Al13n on 02/23/06 23:14

"Jake" <offsky@gmail.com> 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]]

Try this
\[{2}(?:[^]|]+?\|)?([^]]+?)\]{2}

-- It searches for yyy| but makes it optional, either way it will capture
xxx into backreference 1.

You can test it here: http://tinyurl.com/jrz2u

When plugging it into a preg/ereg statement (I've only tested it with preg
though), it's good practice to double up your backslashes -- one for php,
one for the regex engine. So it would look like

$text = ereg_replace('\\[{2}(?:[^]|]+?\\|)?([^]]+?)\\]{2}', '\\1', $text);

-Allen

--
Few of my projects recent projects--
Online Regex find/repalce utility: http://rereplace.com
Command-based online image editor: http://theprawn.com/imagiine

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация