1

I am Tryting to show wiki text in HTML in my app(Using cakephp). I use this expression for <h4>,<h5>,<h6>

'/^==== (.*) ====$/'
    =>  '<h4>\1</h4>',
    '/^===== (.*) =====$/'
    =>  '<h5>\1</h5>',
    '/^====== (.*) ======$/'
    => '<h6>\1</h6>',

[http://www.wikipedia.org Wikipedia] will be shown as <ahref="www.wikipedia.org">Wikipedia </a>

[5|Text] will show like <a href="http://fillpage/5/page_slug">Text</a>

[[6#HeadingB|Text ]] will shown as <ahref="http://fillpage/6/page_slug#HeadingB>Text</a>

[[6#HeadingB]] will shown as <a href="http://fillpage/5/page_slug">PageTitle</a>

[media:631|Description|Position] will shown as <img class="position" src="http://fullpath/lang_code/631.jpg">Description

I wan't to know how to make such regex for links(exactly like Wikipedia shows.) how to make it done. And how to match space b/w two brackets for links.

4

1 回答 1

1

匹配\[(.*?) +(.*)\]

并替换为:$2

或者如果你在 php 中使用 preg

去做这个:

'/\[(.*?) +(.*)]$/'

并用反斜杠接受它们,如下所示:'<a href="\1">\2</a>'在数组中作为上述模式的值作为键。

那是维基百科的。您可以访问http://gskinner.com/RegExr/并使用右栏中的模式参考。

希望能帮助到你。

于 2013-09-07T18:54:18.300 回答