MediaWiki 维基文本模板的正则表达式

发布于 2024-12-28 17:48:46 字数 485 浏览 2 评论 0原文

Yaron Koren 的 ReplaceText MediaWiki 扩展允许我使用正则表达式来替换 MediaWiki 中的文本。我有大约 300 个 MediaWiki 页面,其中有两个模板实例。我只想使用正则表达式删除第二个模板。 (替换为任何内容)

我有:

}} <--end of first template-->

{{Template Call

|blahField=blahValue

|blahField=blahValue

|...

}}

我想我想搜索: ^[ \\}} \r \\{{ *? ]

并将其替换为: ^[ \\}} ]

但是当我在 rexv.org

感谢有关正则表达式的一些帮助。

Yaron Koren's ReplaceText MediaWiki extenion allows me to use regular expressions to replace text in MediaWiki. I have about 300 MediaWiki pages that have two instances of a template. I want to delete only the second template using regular expressions. (replace it with nothing)

I have:

}} <--end of first template-->

{{Template Call

|blahField=blahValue

|blahField=blahValue

|...

}}

I think I want to search for: ^[ \\}} \r \\{{ *? ]

and replace it with: ^[ \\}} ]

but this is not producing the result I want when I test it at rexv.org

Appreciate some help with regular expressions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我们只是彼此的过ke 2025-01-04 17:48:46

扩展页面上显示

允许的正则表达式集基本上是 PHP 和 MySQL 正则表达式集的一小部分(仅在 MySQL 上进行过测试 - 是否适用于其他数据库系统尚不清楚)。搜索字符串中可以使用的字符为“( ) . * + ? [ ] |”

所以也许您使用的字符不起作用。是否有可能 \ 搞砸了?

On the extension page it says

The set of regular expressions allowed is basically a small subset of the PHP and MySQL regular-expression sets (it has only been tested with MySQL - whether it works on other database systems is unknown). The characters that one can use in the search string are "( ) . * + ? [ ] |"

So maybe the characters you are using don't work. Is it possible the \ is messing it up?

恋你朝朝暮暮 2025-01-04 17:48:46

ReplaceText 不适合此类替换。使用 PyWikipediaBot 或 AutoWikiBrowser。

ReplaceText is not suitable for such replacements. Use PyWikipediaBot or AutoWikiBrowser.

我纯我任性 2025-01-04 17:48:46

我在这里有一些技巧:

  1. 将您的 {{Template Call}} 模板清空。
  2. 使用 ReplaceText 将 \{\{ *Template[ _]Call (使用正则表达式以避免格式错误的调用)替换为 {{subst:Template Call
  3. 然后,您的 Template Call 位置将被 {{Template Call}} 的内容替换,该内容是空的。

希望有帮助。

I have some hack here:

  1. Make your {{Template Call}} Template to empty.
  2. Use ReplaceText to Replace \{\{ *Template[ _]Call (with regex to avoid badly-formatted calls) to {{subst:Template Call.
  3. Then the places you have Template Call will be replace by contents of {{Template Call}}, which is empty.

Hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文