Forum:Bot search and replace

I'd like to replace all links in a wiki that look like this *PAGENAME at Tolkien Gateway with a template looking like this * The structure is always the same, but PAGENAME differs. Is that possible using AWB or Pywikipediabot? If so... how?

Thanks for your help. -- Weas-El ✉  15:02, November 3, 2011 (UTC)


 * At least for the template call, you should use the magic word . AWB may be able to do it, Pywikipedia could definitely have a script written for it that would allow it to perform that action if it doesn't already have the capability.


 * You could likely use AWB with a regular expression in order to express PAGENAME or at least to capture it in the find. Not sure on what it is you would use though.--


 * "PAGENAME" probably was a bad choice for my parameter name. This is just the name of the linked page, but not necessarily equal to.
 * @Godisme: What could that regex look like? The expressions don't have the same length... -- Weas-El ✉  15:15, November 3, 2011 (UTC)


 * I read some help pages now, but I wasn't able to figure out how to create an appropriate regular expression yet. It would be easier if the page title had always the same length. Do you know any experienced pywikipediabot users I could ask? -- Weas-El ✉  20:42, November 3, 2011 (UTC)

You might find the fixes.py script a useful source of advanced replacement examples. — Sovq 21:45, November 3, 2011 (UTC)


 * That means I'll have to write my own script for this? -- Weas-El ✉  22:31, November 3, 2011 (UTC)


 * That would be an option, yes, but instead of writing the whole script you can do what I do - change the replacement strings in one of the fixes.py functions (I usually modify the 'HTML' function) and the call fixes.py -FUNCTIONNAME though pywikipediabot. If you give links to a few pages which contain the string you want to replace, I could try and write an appropriate command to do the replacement. — Sovq 07:12, November 4, 2011 (UTC)


 * That would be a great help, thank you. I'm actually just beginning to learn using python. I've made use of the standard scripts before, but never changed their source code before yesterday.
 * You'll find a list of all pages in question here (all but user and user talk namespace). I'll be not at home for the next two days by the way, and probably won't log in during this time. -- Weas-El ✉  12:31, November 4, 2011 (UTC)