Jump to content

Wikipedia talk:AutoWikiBrowser/Find and replace

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by NotThatAnonymous (talk | contribs) at 03:03, 16 September 2016 (Match if two words are the same?: new section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A rule does not work like I want it to

Here are a rule I have created in advanced find and replace:

Find: {{wikipedia|%%pagename%%}}
Replace: {{wikipedia}}

(I also tried with %%title%% and %%basepagename%% but to no avail.)

Let us say that an article titled “Foobar” has the following therein: {{wikipedia|Foobar}}

I want and expect my rule to replace that with simply {{wikipedia}}, but AutoWikiBrowser makes no change to the page.

I have the “Regular expression” box ticked off, by the way. When I tick it on, it replaces {{wikipedia|Foobar}} with {{wikipedia}}|{{wikipedia}}, which is, obviously, not what I want.

To sum it up: I want to remove the parameter of the {{wikipedia}} template in articles but only if the parameter is the same as the title of the article.

Can anyone please please help me with this?
PapíDimmi (talk | contribs) 00:09, 25 June 2016 (UTC)[reply]

I don't know if %%pagename%% is supposed to not work without regex, but if you use regex, you need to "escape" special characters in the "Find" string by adding backslashes: \{\{wikipedia\|%%pagename%%\}\}. SiBr4 (talk) 14:24, 25 June 2016 (UTC)[reply]
(My apologies for the late reply.) That works perfectly. Thank you!
PapíDimmi (talk | contribs) 15:58, 4 July 2016 (UTC)[reply]

Switch order of two fields

Is there a way I could switch the order of two sections?

For example, I would like to find this:

| source = {{own}}
| date = 2009-01-01

and replace it with this:

| date = 2009-01-01
| source = {{own}}

I would like to switch the order of these two fields sections, keeping the name of the sections and their content, simply switching the order (so the date the source remains, but the order changes).

My reason for this is due to the "date" field displaying before the "source" field in Wikimedia Commons file descriptions.

Thanks, OSX (talkcontributions) 04:39, 29 June 2016 (UTC)[reply]

You literally copied what I wrote. (proofs: Screenshot 1, Screenshot 2.) I do not have a problem with that; I just find it funny.
PapíDimmi (talk | contribs) 17:47, 5 July 2016 (UTC)[reply]
What's the context? I assume this is within a particular template, which? —  crh 23  (Talk) 09:44, 29 June 2016 (UTC)[reply]
It is for Commons:Template:Information. Thanks, OSX (talkcontributions) 12:03, 29 June 2016 (UTC)[reply]
Will the options always be adjacent? —  crh 23  (Talk) 12:47, 29 June 2016 (UTC)[reply]
Yes. OSX (talkcontributions) 13:06, 29 June 2016 (UTC)[reply]
Find ({{Information.*?)(\s?\|\s*?source\s*?=.*?)(\s?\|\s*?date\s*?=.*?)(\s?\|) and replace with $1$3$2$4, with SingleLine ticked. I haven't tested this much, and there will probably be cases where it does an incorrect replacement, but it should work usually. Make sure to check your edits! —  crh 23  (Talk) 14:05, 29 June 2016 (UTC)[reply]
Also, check that the change is welcome: it is a very minor change, so it might be unwelcome to make it on its own. —  crh 23  (Talk) 14:06, 29 June 2016 (UTC)[reply]
Thanks for the code. For me though, it does not work. I have copied your "find" code into the "find" field and $1$3$2$4 into "replace with", with SingleLine ticked. OSX (talkcontributions) 14:24, 29 June 2016 (UTC)[reply]
Do you have Regex ticked too? —  crh 23  (Talk) 14:42, 29 June 2016 (UTC)[reply]
I do now and that fixed it! Thank you very much for your help :) OSX (talkcontributions) 14:50, 29 June 2016 (UTC)[reply]
You're welcome! Sorry, forgot to mention it (doesn't show in the regex tester tool, for obvious reasons). —  crh 23  (Talk) 16:11, 29 June 2016 (UTC)[reply]

Move bold

I want to replace this:

'''Any words (born {{birthdate|any number|any number|any number}})'''

with this:

'''Any words''' (born {{birthdate|any number|any number|any number}})

I want to keep the words and numbers, but move the bold so that the only the “Any words” at the start is bold and not the whole thing.

I tried this:
Find:

'''(.*) (born {{birthdate|(.*)|(.*)|(.*)}})'''

Replace:

'''$1''' (born {{birthdate|$2|$3|$4}})

…but that did not work.

Example

Replace this:

'''John Smith (born {{birthdate|1973|12|05}})'''

with this:

'''John Smith''' (born {{birthdate|1973|12|05}})

Could anyone please help?
PapíDimmi (talk | contribs) 23:36, 4 July 2016 (UTC)[reply]

Remember to escape special characters. I use regex101 for regex debugging, it will break it down for you. —  crh 23  (Talk) 18:07, 5 July 2016 (UTC)[reply]
Ah, silly me. I forgot to escape the special characters. That online regex tester is really helpful, by the way. Thank you so much for your help! Hopefully I will be able to figure out future problems on my own instead of having to ask here.
PapíDimmi (talk | contribs) 22:23, 5 July 2016 (UTC)[reply]

Add to bottom of page

Hi. I want to use AutoWikiBrowser to add a category to a page if it does not contain a template.

I added the template to the “Not contains” section in a rule in advanced find and replace, and then I tried with .*? and also the s modifier and replacing it with

$1
[[Category:Categoryname]]

…but that did not work at all.

I want to add a category to every page that does not include a specific template. Is there a way to do this?
PapíDimmi (talk | contribs) 14:07, 6 July 2016 (UTC)[reply]

If you absolutely mean bottom of the page, do a append text under the "More..." tab and a skip if doesn't contain (if it has option do skip if contains {{template| —  crh 23  (Talk) 14:14, 6 July 2016 (UTC)[reply]
You mean using the add category feature in the “More…” tab and setting skip options in the “Skip” tab? I want to add this category among many other changes, and I do not want to skip all of them just because the page does not include a template. I guess I could disable everything except the category add and do one go to add the category and then another with the other changes later. It is not what is most ideal to me, but since it apparently is my only option, I guess it will have to do. Thanks for your help.
PapíDimmi (talk | contribs) 14:34, 6 July 2016 (UTC)[reply]

Replace XXxYYpx with XXpx

I want to replace "XXxYYpx" with "XXpx" in file names if both numbers are the same.

E.g., replace [[File:Some kind of image.png|340x340px|Some kind of image caption]] with [[File:Some kind of image.png|340px|Some kind of image caption]].

(I do not know how I match two of the same string of characters with RegEx.)

I thought that general fixes does this, but apparently it does not.
PapíDimmi (talk | contribs) 17:14, 9 July 2016 (UTC)[reply]

Captured groups can be backreferenced in the Find string using a backslash followed by the number: (\d+)x\1px$1px. Note that 340x340px and 340px aren't always interchangeable: any vertical image will render larger with the second code than with the first. SiBr4 (talk) 18:04, 9 July 2016 (UTC)[reply]
Thank you!
PapíDimmi (talk | contribs) 09:36, 10 July 2016 (UTC)[reply]

Match if two words are the same?

I want to replace something with something else—but only if two strings are exactly the same.

If they are not the same, I want to replace it with something else.

To be more specific, I want to replace [[Wikipedia:X|X]] (where both “X”s are the same word or words) with {{w|X}}, but if they are not the same word or words, I want to replace [[Wikipedia:X|Y]] (where “X” is one word, and “Y” is another) with {{w|X|Y}}.

Examples
  • Replace [[Wikipedia:Video game|Video game]] with {{w|video game}}
  • Replace [[Wikipedia:Fireworks|tree]] with {{w|Fireworks|tree}}

PapíDimmi (talk | contribs) 03:03, 16 September 2016 (UTC)[reply]