User:Becasita/SubPages/Regex

From Yugipedia
Jump to: navigation, search

Useful regex to update pages.
Unless stated otherwise:

  • Global match (replace all); g modifier;
  • No single line;
  • Multiple line; m modifier; (It doesn't really matter here, though.)
  • Case sensitive;

Usually, the text editors have check boxes for these options, so the modifiers are not needed. Single line is usually unchecked by default.
To make use of this, just copy the code of the page you want to change to a text editor. Then open the "Find & Replace" box. Find what's on the "Find" row and replace with what's on the respective "Replace" row.

Set galleries and lists[edit]

General[edit]

From a list/gallery, generate for the other regions
  • -{{ subst:#var: $rg }}
{{ subst:#replace: {{ subst:#explode: {{ subst:#explode: {{subst:PAGENAME}} | \( | -1 }} | - | 1  }} | \) }}

Lists[edit]

To remove passcode entries:
Find \n\s*\| \[\[\d{2,}\]\]
Replace

To add the {{Card name}} template or to replace already existing localized names with it:
Find \|\-\s*?\n\s*\|\s*\[\[(.*?)\]\]\s*?\n\s*\|\s*\[\[(.*?)(\|(.*?))?\]\]((.*?)*)\s*?\n\s*\|\s*[^\[]*
Replace |-\n| [[$1]]\n| [[$2$3]]$5\n| {{Card name|$2|{{ subst:#var: $ln }}}}\n| 

Notes:

  • This is made to use in conjunction with Dino's boilerplate. To use it separately, {{ subst:#var: $ln }} should be substituted with the language index. Languages indexes can be checked at {{ISO 639}}.

To change the line containing the rarities:
Find \|\-\s*?\n\s*\|\s*\[\[(.*?)(<cards' set number>)\]\]\s*?\n\s*\|\s*\[\[(.*?)\]\]((.*?)*)\s*?\n\s*(\|\s*[^\[]*?\s*?\n\s*)?\|\s*\[\[(.*?)\]\](.*)
Replace |-\n| [[$1$2]]\n| [[$3]]$4\n$6| [[Common]]

Notes:

  • <cards' set number> should be substituted with the cards' set number (e.g., 046) of the entries to be changed, separated by a pipe (|). E.g., 001|046|101; To change all the entries it should be left empty (());
  • Common should be changed to the rarity that will replace the previous one;
  • To replace entries with a specific rarity, the last (.*?) should be substituted with the rarity to be replaced.

To change the last line with a template that will get the card category:
Find \|\-\s*?\n\s*\|\s*\[\[(.*?)\]\]\s*?\n\s*\|\s*\[\[(.*?)(\|(.*?))?\]\]((.*?)*)\s*?\n\s*(\|\s*[^\[]*?\s*?\n\s*)?\|\s*\[\[(.*?)\]\]\s*?\n\s*\|\s*(\s*\[\[(.*?)\]\])*
Replace |-\n| [[$1]]\n| [[$2$3]]$5\n$7| [[$8]]\n| {{subst::User:Becasita/SubPages/Templates/CardType|$2}}

Notes:

  • This should only be used if there already is a last line with the card type and if there is no line with the passcode.
  • To convert to {{Set list}}: $1; $2; $8.

Galleries[edit]

To add the {{Card name}} template or to replace already existing localized names with it:
Find \s*<\s*\/?\\?\s*br\s*\/?\\?\s*>\s*\[\[(.*?)(\|(.*?))?\]\].*
Replace <br />[[$1$2]]<br />{{Card name|$1|ln}}

Notes:

  • ln should be substituted with the language index or with {{ subst:#var: $ln }} if used with the boilerplate.

To change multiple entries to JPG:
Find (.*?).png(\s*)(.*?)(<cards' set number>)(.*)
Replace $1.jpg$2$3$4$5

Notes:

  • <cards' set number> should be substituted with the cards' set number (e.g., 046) of the entries to be changed, separated by a pipe (|). E.g., 001|046|101;
  • To change to PNG instead, just substitute jpg with png.

Convert to {{Set gallery}}:
Find .*?\[\[(.*?)\].*?\[\[(.*?)\].*?\[\[(.*?(\|(.*?))?)(\|.*?)?\].*
Replace $1; {{ subst:#if: $5 | $5 | $3 }}; {{subst:R|$2|full=1}}

Bot[edit]

Search categories:
Find (.*?) -> (.*)
Replace \(\\*|=\) \*$1\$\n\$1 $2\n
Add several entries to the XML settings:
Find (.*?) → (.*)
Replace
<Replacement>\n
  <Find>$1</Find>\n
  <Replace>$2</Replace>\n
  <Comment></Comment>\n
  <IsRegex>false</IsRegex>\n
  <Enabled>true</Enabled>\n
  <Minor>false</Minor>\n
  <BeforeOrAfter>false</BeforeOrAfter>\n
  <RegularExpressionOptions>IgnoreCase</RegularExpressionOptions>\n
</Replacement>

Other[edit]

Removing erroneous DR04 entries
\n\s*\{\{Card table set\|DR04-(FR|IT|DE|SP)\d+\|Dark Revelation Volume 4\|[\w\s]+\}\}
\n\s*'*\[\[Dark Revelation Volume 4\]\]'* \(\[\[DR04-(FR|IT|DE|SP)\d+\]\] - \[\[[\w\s]+\]\]\)

Removing unreleased gallery entries
(.*?)-(FR|IT|PT|SP)(.*?)UE(.*?)Flaming Eternity\]\]\n

OR

(.*?)SDWS-(EN|FR|DE|IT|PT|SP)(.*?)UE(?!-(OP|GC|CT|RP))(.*?)\n

Common to Short Print at galleries
(.*?)-C-(.*?)(01|43|69|80)\](.*?)\[C\](.*)$1-SP-$2$3]$4[SP]$5

OR

(.*?)-C-(.*?)(\s*?)\s{1}(.*?)(14|15)\](.*?)\[C\](.*)$1-SP-$2$3$4$5]$6[SP]$7

Notes: May fail;


To add a set to {{CardTable2}}
\{\{Card table set/header\|kr\}\}(.*?)\{\{Card table set/footer\}\}{{Card table set/header|kr}}$1{{Card table set|ST16-KR0|Starter Deck 2016|Common}}\n{{Card table set/footer}}

Notes: Single line (s modifier). Very fragile (pay special attention!).


Duel Transer galleries
\|\-\s*?\n\s*\| \[\[(.*?)\]\]\s*?\n\s*\| \[\[(.*?)(\|(.*?))?\]\]((.*?)*)\s*?\n\s*(\| [^\[]*?\s*?\n\s*)?\| \[\[(.*?)\]\]\s*?\n\s*\| (\s*\[\[(.*?)\]\])*|-\n| [[$2 \(Duel Transer\)|{{ subst:#if: $4 | $4 | $2 }}]]\n| [[\n| {{subst::User:Becasita/SubPages/Templates/CardType|$2}}

Link with dab templates
\[\[([^\[]*?) \((anime|manga)\)\|(\1)\]\]{{$2|$3}}

To remove links at card lores (for a comparison)
(\[\[[\w\s\-]*\||\[\[|]])

To use at Gallery section of set articles
\[\[(.*?)\|(.*?)\]$2<br />[[$1|Limited Edition]

To generate galleries from lists (still needs some manual control for multiple rarities)
{{subst:Card image name|$2}}-ABBR-{{ subst:#var: $rg }}-{{subst:R|$8}}-UE.png {{subst:!}} [[$1]] \([[{{subst:R|$8}}]]\)<br />[[$2$3]]{{ subst:#ifeq: {{ subst:#var: $ln }} | en ||<br />{{Card name|$2|{{ subst:#var: $ln }}}}}}