Difference between revisions of "Help:Regular expressions"
From Nookipedia, the Animal Crossing wiki
(Added an online visual regex tester) |
SuperHamster (talk | contribs) (→Examples: +example) |
||
Line 17: | Line 17: | ||
== Examples == | == Examples == | ||
Below is a list of examples of regular expressions that may help you on the wiki. Feel free to expand this list. | Below is a list of examples of regular expressions that may help you on the wiki. Feel free to expand this list. | ||
+ | |||
+ | * Replacing instances of <code><nowiki>{{I|Item Name}}</nowiki></code> with <code><nowiki>{{I|Item Name|New Horizons}}</nowiki></code> (Python): | ||
+ | :Find: <code><nowiki>{{I\|(?!.*\|)(.*?)}}</nowiki></code> | ||
+ | :Replace: <code><nowiki>{{I|\1|New Horizons}}</nowiki></code> | ||
* Matching a multi-line Foreignname template and adding a new "See also" section after it (Python): | * Matching a multi-line Foreignname template and adding a new "See also" section after it (Python): | ||
:Find: <code><nowiki>{{Foreignname([\s\S]*?\n}})</nowiki></code> | :Find: <code><nowiki>{{Foreignname([\s\S]*?\n}})</nowiki></code> | ||
− | :Replace: <code><nowiki>{Foreignname\1\n\n==See also==</nowiki></code> | + | :Replace: <code><nowiki>{{Foreignname\1\n\n==See also==</nowiki></code> |
[[Category:Nookipedia]] | [[Category:Nookipedia]] |
Revision as of 03:48, December 29, 2020
A regular expression (regex) is a sequence of characters defining a search pattern. On the wiki, they are commonly used for finding and replacing text through Special:ReplaceText (staff only), AutoWikiBrowser, Pywikibot, or Scribunto/Lua modules.
Each tool/programming language uses its own ruleset for regular expressions:
- Special:ReplaceText supports a small subset (
( ) . * + ? [ ]
) of the PHP and MySQL/PostgreSQL regular-expression set. - AutoWikiBrowser uses .NET regular expressions.
- Pywikibot uses Python regular expressions.
- Lua/Scribunto pattern are similar to regular expressions, but not identical. See this page for a list of differences.
If you need help with regular expressions, you may post on the talk page, or join the Nookipedia Discord and ask in the #wiki-tech channel.
Testing
There are several online tools to test our patterns. A small selection is listed below.
Examples
Below is a list of examples of regular expressions that may help you on the wiki. Feel free to expand this list.
- Replacing instances of
{{I|Item Name}}
with{{I|Item Name|New Horizons}}
(Python):
- Find:
{{I\|(?!.*\|)(.*?)}}
- Replace:
{{I|\1|New Horizons}}
- Matching a multi-line Foreignname template and adding a new "See also" section after it (Python):
- Find:
{{Foreignname([\s\S]*?\n}})
- Replace:
{{Foreignname\1\n\n==See also==