Mediawiki链接的正则
我需要帮助尝试修复以在MediaWiki网站上使用的正则GEGEX,尤其是在链接领域。
我要完成的是转动[[< name> (<标识符>)|< name>]]
仅{{{< template> |< |< link> | |> |>}}}}}}
我似乎是我制作的。搞砸了它的工作方式。
以这两个字符串为例:
====[[<link #1>]] [[<link #2 name> (<link #2 identifier>)|<link #2 name>]]====
[[<link #3 name> (<link #3 identifier>)|<link #3 name>]]
我的正则是/\ [\ [(。*?)\((。*??)\)\ |(。*??)] 在情况下,结果应该刚刚捕获
[[&lt; link#2 name&gt; (&lt; link#2标识符&gt;)|&lt; link#2名称&gt;]]
和[[&lt; link#3 name&gt; (&lt; link#3标识符&gt;)|&lt; link#3 name&gt;]]
相反,Regex捕获[[&lt; link#1&gt;]] (&lt; link#2标识符&gt;)|&lt; link#2名称&gt;]]
和[[&lt; link#3 name&gt; (&lt; link#3标识符&gt;)|&lt; link#3名称&gt;]]
,当我替换为{{&lt; template&gt; | $ 1 | $ 2}}} AS:
===={{<template>|<link #1>]] [[<link #2 name>|<link #2 identifier>}}====
{{<template>|<link #3 name>|<link #3 identifier>}}
我需要帮助。我尝试在互联网上查找,但我找不到一种方法来防止正则试图与其他链接重叠
I need help trying to fix a regex to use on a MediaWiki site, particularly in the field of links.
What I want to accomplish is turning [[<name> (<identifier>)|<name>]]
to just {{<template>|<link>|<identifier>}}
but the regex I made seems to be screwing around with how it works.
Take these two strings for instance:
====[[<link #1>]] [[<link #2 name> (<link #2 identifier>)|<link #2 name>]]====
[[<link #3 name> (<link #3 identifier>)|<link #3 name>]]
My regex is /\[\[(.*?) \((.*?)\)\|(.*?)]]/gm
Under circumstances, the result should have just caught [[<link #2 name> (<link #2 identifier>)|<link #2 name>]]
and [[<link #3 name> (<link #3 identifier>)|<link #3 name>]]
Instead, the regex captures [[<link #1>]] [[<link #2 name> (<link #2 identifier>)|<link #2 name>]]
and [[<link #3 name> (<link #3 identifier>)|<link #3 name>]]
, leaving the end result when I replace with {{<template>|$1|$2}}
as:
===={{<template>|<link #1>]] [[<link #2 name>|<link #2 identifier>}}====
{{<template>|<link #3 name>|<link #3 identifier>}}
I need help with this. I tried looking around the internet, and I can't find a way to prevent the regex from trying to overlap with other links
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
regex demo 。 详细信息:
\ [\ [
- a[[
string(((?:(?)) ))*)
- 第1组:除以外的零或更多字符(
and)
每个都不启动[[[ substring
\ s+
- 一个或多个whitespaces\(
- a)(
char((? [)[^()])*)
- 第2组:零或更多字符以外的其他字符((
and)
每个都不启动[[
substring\)\ |
- a)|
String(。*?)
- 组3:任何零或除线断裂字符以外的其他字符]]
字符串。You can use
See the regex demo. Details:
\[\[
- a[[
string((?:(?!\[\[)[^()])*)
- Group 1: zero or more chars other than(
and)
each of which does not start a[[
substring\s+
- one or more whitespaces\(
- a(
char((?:(?!\[\[)[^()])*)
- Group 2: zero or more chars other than(
and)
each of which does not start a[[
substring\)\|
- a)|
string(.*?)
- Group 3: any zero or more chars other than line break chars as few as possible]]
- a]]
string.