User talk:Infinite/Elites
From Guild Wars Wiki
Jump to navigationJump to search
Links[edit]
Was this what you were after? It was a 2 minute job with RE replace, your edit summary implied you were going to do it all by hand :P Loggy (talk) 12:37, 9 February 2018 (UTC)
- Oh my god, YES! Please teach me about RE replace. It's a Python thing, right? That's a language I have almost zero knowledge on so far, but it is on the list of languages to pick up. Either way, thank you so much for doing this work at a fraction of the time I would have taken for it! I feel the love! - Infinite - talk 20:00, 9 February 2018 (UTC)
- Haha I'm glad to have helped. As I'm not really doing anything while waiting for FA, thought I might as well add explanation...
- I think it started out in Perl, but yeah Python implements a very similar version I think (screw Perl, I know nothing about it except that trying to follow it makes me want to embed my head in the nearest wall). Actually to do this I used the RE replace feature of notepad++ as it makes it quite easy to search for unintended side effects too.
- Anyway, the logic behind this: RE matches bits of strings, and lets you "keep" sections of them to include in a replacement. So here it was a case of finding any image tag ending with |px]] and adding the link of the skill's name to it, so:
[[File:Cleave.jpg|Cleave|45px]]
- becomes
[[File:Cleave.jpg|Cleave|45px|link=Cleave]]
- This document is my general reference for all this stuff, and serves as quite a nice general introduction to a lot of the more common features.
- But anyway, in this case the thing to try and match is the _entire_ image tag, which looks like this, and preferably not other images like the prof icons (but they're 48px so won't match):
[[File:(.*?)|(.*?)|45px]]
- The (.*?) is made up of several parts: the dot in RE means match any character except newlines (IE, the anything but \r and \n), and *? means match as few as possible instances of whatever goes before. Because of the way the tag is put together, this eats up the file name and skill name only because it has to match the pipes as well, and can't cross lines thanks to the dot. The brackets mean to save it in a "group" for later.
- Plot twist: RE has a lot of reserved characters which wiki syntax likes to use, which you escape by putting [] around the offending character. In our case, [, ], | and maybe : (I can never remember about colons) all have other meaning to the RE engine so we have to turn the whole thing ugly to make it work:
[[][[]File[:](.*?)[|](.*?)[|]45px[]][]]
- Then it's all down to the replace line. In np++ you retrive what the groups matched using \1, \2, \3 etc etc. So it's a simple matter to reconstruct the tag, with the link on the end. The escaping isn't needed on the replace line either.
[[File:\1|\2|45px|link=\2]]