Wikipedia talk:AutoWikiBrowser/Find and replace/Archive 1
This is an archive of past discussions about Wikipedia:AutoWikiBrowser. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 |
RefList
Sorry, Rookie AWB Question: I noticed that AWB changes the "references/" to "reflist"...which is not always perferable...Are there parameters around this? Is it only when "reflist" has no parameters? I was hoping to find a bit more description of functions here...Like "what" gets replaced and "Why" (meaning which MOS or guildline it is trying to standardize...) -- Mjquin_id (talk) 18:14, 20 November 2008 (UTC)
- It changes it in only certain criteria (dont ask me specifically what). There are some changes that have no appearance changes, but some, with certain div's round it, that would change it, and hence, AWB leaves alone. —Reedy 18:22, 20 November 2008 (UTC)
- AWB is changing "references/" to "reflist" only if there is div class small around it. This change doesn't affect the appearance of the references in the article. -- Magioladitis (talk) 18:28, 20 November 2008 (UTC)
How to replace in more than one line?
I can't understand how to replace in more than one line. For example, in article XXX, how do I replace:
Line 1 Line 2 Line 3
with:
Line 1 Line 3
Notice that I don't want an empty line like this:
Line 1 Line 3
Thank you very much. --Tintero (talk) 18:49, 19 February 2009 (UTC)
- Line 1\r\n --> "" —Reedy 23:40, 19 February 2009 (UTC)
- I had tried, but continues not working. Could you be more specific? Thanks, --Tintero (talk) 14:21, 20 February 2009 (UTC)
- Replace "Line1\r\n" with "" (ie nothing) —Reedy 14:41, 20 February 2009 (UTC)
- What is wrong? [1] And, I want to delete Line 2, do you mean that the line I want to delete depends on the previous one? Because it may vary. --Tintero (talk) 15:27, 20 February 2009 (UTC)
- Ah, sorry. Duh. You want Line 2\r\n then. By "" i mean nothing, put nothing at all in the replacement box. Basically, you need to match the line break, so the \r\n matches the newline and the carriage return —Reedy 19:46, 20 February 2009 (UTC)
- T_T [2] I had tried to activate and deactivate all options, and it didn't detect the text and apply the change. Maybe it's because I'm not using it on Wikipedia (Wikia). Thank you very much for your patience, --Tintero (talk) 00:10, 21 February 2009 (UTC)
- Ah, sorry. Duh. You want Line 2\r\n then. By "" i mean nothing, put nothing at all in the replacement box. Basically, you need to match the line break, so the \r\n matches the newline and the carriage return —Reedy 19:46, 20 February 2009 (UTC)
- What is wrong? [1] And, I want to delete Line 2, do you mean that the line I want to delete depends on the previous one? Because it may vary. --Tintero (talk) 15:27, 20 February 2009 (UTC)
- Replace "Line1\r\n" with "" (ie nothing) —Reedy 14:41, 20 February 2009 (UTC)
- I had tried, but continues not working. Could you be more specific? Thanks, --Tintero (talk) 14:21, 20 February 2009 (UTC)
Using it on wiki wouldn't be the problem. And you shouldnt need anything but enabled checked... —Reedy 22:00, 21 February 2009 (UTC)
- I thought \r\n were regular expressions so I suposed Regex should be checked. In any case I tried that before too. --Tintero (talk) 19:32, 22 February 2009 (UTC)
I only use \n. Rich Farmbrough, 11:10 2 March 2009 (UTC).
- Thanks for all. I finally found the way to do it, using the advanced replace. Greetings, --Tintero (talk) 13:48, 2 March 2009 (UTC)
Do not replace text which is part of url?
I would like to replace .pdf on every page of our wiki with [[.pdf]] apart from when it is included in a URL - ie [http://www.mydomian.com/doc/example.pdf Example] Cjchilling (talk) 08:14, 17 May 2009 (UTC)
Case change
Any way to change the case of a letter? Rocket000 (talk) 17:11, 5 January 2010 (UTC)
Missing explanation in Advanced section
It is said in the Advanced section of the Find and replace page:
Rule each one of these can be nested so that if the upper most rule is satified then AWB will process the next rule below.
As an AWB beginner using the Help page, I find that text ambiguous at best: does that text refer to Rules or to Subrules really? Say you create 2 Rules (not Subrules), what happens: are the rules independant OR are they additive OR are they mutually exclusive? I'm not sure that is explained in this document... --AlainR345Techno-Wiki-Geek 18:51, 8 May 2010 (UTC)
- Hm... I would say they are independent and additive (if I catch your meaning). If the first rule is acted on, and the second rule then qualifies (because the first rule changed the text into something the second rule recognized), it will run as well. The nested refers to subrules.
Rule Subrule Subsubrule Subrule 2
- In theory none of the subrules will act if "rule" doesn't, and Subsubrule will only act if Subrule does. –xenotalk 19:51, 8 May 2010 (UTC)
Change edit summary
The second question is about edit summaries.
Once I have done a regex replacement, say Don't -> Do not, the summary tab displays this.
If, however, I decide to cancel the operation, as it is in a quote etc., how do I remove the summary for "Don't -> Do not" or am I stuck with it? Chaosdruid (talk) 19:52, 3 February 2011 (UTC)
- Edit it manually? (I think there's a tab for that, no?) –xenotalk 20:55, 3 February 2011 (UTC)
- The only tab I can see is
- Edit box|History|What links here|Edit Summary
- It will not allow me to type into it or remove any of the info. Chaosdruid (talk) 21:21, 3 February 2011 (UTC)
character removal around a string
Hi
I am trying to set up a rule to replace a series of deboldening.
I have the ind param set up to detect the entries but cannot work out how to keep the "filling"
Find:\* ' ' ' (\S.*\S) ' ' '
Replace:
Text to search:* ' ' ' Harry ' ' ' played by
Result:...{* ' ' ' Harry ' ' '}
- .
- ....{* ' ' ' Harry ' ' '}
- .
- ....{Harry}
The find param works fine, however I cannot work out how to keep the removed text so that it is replaced correctly. If I put (\S.*\S) into the replace field all I get back is
Result:(\S.*\S)
Obviously either I am missing some way of giving the string a name to recall, or some other function. Chaosdruid (talk) 19:45, 3 February 2011 (UTC)
- $1 maybe? –xenotalk 20:54, 3 February 2011 (UTC)
- I am a silly bugger lol, sometimes it's the obvious things lmao - I kept trying to put $1 in the FInd as well as the Replace, but its just in the replace isnt it...
- Yup, sure enough I need to put "Replace:* $1" and that returns it in full - thx for that :¬) Chaosdruid (talk) 21:28, 3 February 2011 (UTC)
- Sometimes it takes another set of eyes to notice the blindingly obvious =) As for your question below, I'm afraid I don't have an answer for that ;p –xenotalk 21:30, 3 February 2011 (UTC)
- (ec)
- And now comes the hard? part - now that is working the problem is that every page has ' ' ' ' ' XXXXX ' ' ' ' ' in the opening few words and I need to exclude them, otherwise it will debolden and leave as italics.
- Any ideas on that one ? Chaosdruid (talk) 21:32, 3 February 2011 (UTC)
- It shouldn't match words in the lead because you have a preceding bullet point, no? –xenotalk 21:34, 3 February 2011 (UTC)
- Sorry, I missed a step there! Following on from that I need to have a rule fo r those that do not have the preceeding *
- For example, in the middle of text or as the first words of a paragraph.
- ' ' 'Fred Bloggs' ' ' ([[Jim Tool]]) - The foil for ' ' ' Trevors ' ' ' comic antics
- and the main proponent of misery in the gang.
- That was the missing step - sry about that Chaosdruid (talk) 21:44, 3 February 2011 (UTC)
- You could start the rule with ==(.*?)''' - so it would have to first match two equals signs, then a bunch of other stuff, and then the bolding. That should get you below the lead. Don't forget to replace the bunch of other stuff =]. –xenotalk 21:49, 3 February 2011 (UTC)
- It shouldn't match words in the lead because you have a preceding bullet point, no? –xenotalk 21:34, 3 February 2011 (UTC)
- Sometimes it takes another set of eyes to notice the blindingly obvious =) As for your question below, I'm afraid I don't have an answer for that ;p –xenotalk 21:30, 3 February 2011 (UTC)
K- that is really weird...
Text to search: (always the same )
'''''Harry''''' is a film
==Blah==
'''Harry''' played by '''fred'''
'''Levi''' played by '''Ahmed'''
- So the first way it only replaces the first one after the == (I assume because the rest are not preceded by ==) which gives:
Find:==(.*?) ' ' ' (\S*) ' ' '
Replace:==$1$2
Result:
Harry is a film
==Blah== Harry played by fred
Levi played by Ahmed
- This next one works fine (apart from the first line) as it does a repetitive find and replace:
Find:' ' ' (\S*) ' ' '
Replace:$1
Result:
Harry is a film
==Blah== Harry played by fred
Levi played by Ahmed
- I just need to work out how to make it ignore the first ' ' ' ' ' Harry ' ' ' ' ' is a film - ah well at least I can still use it, just cancel the first edit and then save, annoyingly though it will wstop at every page, even those that need nothing doing as every page has that first ' ' ' ' ' XXX ' ' ' ' '. Chaosdruid (talk) 23:11, 3 February 2011 (UTC)
Category replacement
I want to replace [[Kategoria:Obrazki]] with [[Kategoria:Grafiki]]. What to type in find and replace to do it? I'm a new user of AWB. 85.89.162.235 (talk) 09:39, 9 May 2011 (UTC)
- You have to better use the category replacement instead of the find and replace.
- Go to the "More..." tab. There is a box called "Categories". Choose a task... Replace category and put in the top box Obrazki and on the bottom Grafiki. -- Magioladitis (talk) 10:27, 9 May 2011 (UTC)
Year
Hi, I used AWB for a non-wikipedia project. I wish to find an replace all years.
Exemple : find and replace [[1800]] - [[1801]] - [[1802]] and so on and replace by the same without link : 1800 - 1801 - 1802 and so on.
How can I do ? --62.147.241.53 (talk) 17:20, 8 November 2011 (UTC)
Editing sentences
I need to useAWB to edit some images due to a template change, as such I'll need to wrap square brackets around images that previously didn't have them. As such I'm trying to do "image=image.png" -> "image= [[image.png|128px]]" is there a way I can make find and replace only find this section as otherwise I may end up adding |128px]] to the end of .pngs on the page in places they shouldn't be as "image" is different on every page. 92.17.227.119 (talk) 18:59, 18 January 2013 (UTC)
Please show examples in the manual
Some examples would enhance the descriptions. Particularly some examples about the effect of the Multiline/Singleline options would be useful. Karmela (talk) 19:51, 15 March 2014 (UTC)
Help to replace
Hello. I want to remove a template. The templates has different names in it. For example:
- {{ft|TEAM1}}
- {{ft|TEAM2}}
- {{ft|TEAM3}}
I want to remove {{ft| and }} to have only
TEAM1
TEAM2
TEAM3
I can easily remove with find and replace the {{ft| but I can't do anything with the }}. Any suggestions?
Xaris333 (talk) 16:50, 12 April 2014 (UTC)
- That would probably require a regular expression. Try the following:
- \{\{ft\|(TEAM[123])}} → $1
- with the "Regex" box ticked. This regex works for me in the AWB regex tester. SiBr4 (talk) 17:09, 12 April 2014 (UTC)
- I think I'm now taking your request too literally and assumed you only wanted to find cases where the first parameter is "TEAM1", "TEAM2" or "TEAM3". A regex that catches every usage of a template {{ft}} would be
- \{\{ft\|(.*)}} → $1
- (the .* matches any text except newlines). SiBr4 (talk) 17:15, 12 April 2014 (UTC)
Many thxs!!! Xaris333 (talk) 18:52, 12 April 2014 (UTC)
- Oh. I already replied at WT:AWB. The regex above won't work very well. Try it in the tester and see. Mr Stephen (talk) 21:56, 12 April 2014 (UTC)
- [Reply moved from Wikipedia talk:AutoWikiBrowser ]:
- I would start with something like: find
\{\{ft\|([^}]*)}}
and replace with$1
You may have to throw in a few\s*
to catch unexpected spaces. See Regular expression and test it using the tool. Mr Stephen (talk) 21:21, 12 April 2014 (UTC)
- @Xaris333 and SiBr4: Yes, the above (
\{\{ft\|(.*)}}
→$1
) is bad. The.*
is greedy and will mess up templates later on page. Something like: \{\{\s*[fF]t\s*\|\s*([^}]*)}}
→$1
- Would work. It captures everything up to the closing "}". However, if a template is used internal to the {{ft}} the above regex will not capture the portion beyond the closing of the interior template (i.e. it will mess up). If you expect that there might be interior templates, you need a more complex regex to account for it. Although not extensively tested, this:
\{\{\s*[fF]t\s*\|\s*([^}{]*(\{\{[^}{]*}}[^}{]*)*)}}
→$1
- looks like it works. However, it does not handle issues of malformed occurances, or interior use of a single "{", etc.
- @Xaris333 and SiBr4: Yes, the above (
- @Xaris333: Please: Do not ask the same question on multiple pages at the same time. If you ask in one place and don't get an answer after some days, go ahead and ask in another place (after mentioning in the original location that you have also asked in another location). Asking in multiple places at one time is confusing, and results in much extra work for others. — Makyen (talk) 23:15, 12 April 2014 (UTC); update to reflect content moved from Wikipedia talk:AutoWikiBrowser 23:24, 12 April 2014 (UTC)
- @Mr Stephen and Makyen: Thanks for correcting. I only just noticed that
.*
likes to catch as many text as possible, and that my regex would replace templates outside the desired template when used on wikicode like{{ft|foo}}...text...{{another template}}
. SiBr4 (talk) 23:30, 13 April 2014 (UTC)
- @Mr Stephen and Makyen: Thanks for correcting. I only just noticed that
Help to replace 2
I want to insert a space. For example I want to insert a space after before 15,
one15 to one 15
But if there is another 15 in the article (with space in front of it), not to be replaced.
Xaris333 (talk) 22:28, 14 April 2014 (UTC)
- An example page of what it is that you are actually trying to do would be helpful. However, a find and replace rule using a regular expression to to match the exact example you describe would be:
(one)(15)
→$1 $2
- A more generalized regular expression which will separate any sequence where a ascii letter is followed by a number would be.
([A-Za-z])(\d)
→$1 $2
[NOTE: change of what was a second "A" to "a". This was a typo.]- Note: This does not account for the situations where a non-ascii Unicode letter is followed by a digit. However, that would open up the larger topic of how to deal with Unicode which is much too broad of an issue for this thread. It is also, probably, not something you need to think about at this time. — Makyen (talk) 23:27, 14 April 2014 (UTC); edited due to a typo in the example search text. 00:17, 15 April 2014 (UTC)
User:Makyen, example:
- EnglandU15 to England U15
- FranceU15 to France U15
but if is the article is Germany U15 not to replaced by Germany U15 (with 2 spaces). Xaris333 (talk) 23:35, 14 April 2014 (UTC)
- NOTE: I changed the second example I provided above to correct a typo.
- Your examples help, but I am still guessing about exactly what you desire.
- lowercase letter(s) followed by a single uppercase letter then a number (number length is not considered, and does not matter). Put a space between the lowercase and uppercase letters:
([a-z])([A-Z]\d)
→$1 $2
- lowercase letter(s) followed by at least one uppercase letter then a number (number length is not considered, and does not matter). Put a space between the lowercase and uppercase letters:
([a-z])([A-Z]+\d)
→$1 $2
- As a suggestion, AWB has a Regex Tester. It is accessed from the "Tools" drop-down menu. You can use it to experiment with regular expressions. — Makyen (talk) 00:17, 15 April 2014 (UTC)
Ok. Thx. Xaris333 (talk) 00:23, 15 April 2014 (UTC)
Name parameter
In a template, there is
| name= Sam Andrew
I want to replace everything after | name= with {{PAGENAME}} to have
| name= {{PAGENAME}} Xaris333 (talk) 00:23, 15 April 2014 (UTC)
- OK, this one is more complex. To make a specific regular expression it would help to know:
- The name of the template within which you are wanting to make the change.
- Do we account for the possibility that there might be sub-templates contained within the parameter value?
- If so, might there be sub-sub-templates (how many levels)?
- Do we account for the possibility that there might be wiki markup links (e.g.
[[Wikipedia:AutoWikiBrowser/Find and replace| F&R project page]]
)? - Might there be multiple occurrences of the
|name=
(an erroneous situation)? If so, do we want to detect it and do something about it?
- — Makyen (talk) 02:27, 15 April 2014 (UTC)
- User:Makyen Is the greek version of Template:Infobox football biography but they are the same! Maybe is easiest to remove everything in in name parameter and then add | name= {{PAGENAME}}. I can do the second, but I can't to the first. Xaris333 (talk) 16:42, 15 April 2014 (UTC)
- When I asked for the specific template that you are wanting to operate upon, I did actually mean that I wanted you to tell us the exact template, not one that it is just similar to. In order to prevent the regular expression from acting upon templates other than the one in which you desire to make changes, the regular expression has to include the name of the template desired. In addition, I realized belatedly I should have asked you to provide a pointer to a specific example so that any regular expression could be tested prior to my posting it. However, here is one that should work for Template:Infobox football biography:
(\{\{\s*[Ii]nfobox football biography\s*\|(?:[^\}\{]*(?:\{\{[^\}\{]*\}\}[^\}\{]*)*)\|\s*name\s*=\s*)([^\}\{\|]*(?:\{\{[^\}\{]*\}\}[^\}\{\|]*)*))
→$1{{PAGENAME}}
- NOTE1: Many of the "\" escape sequences in the above regular expression are not actually needed due to the context in which the various special characters are being used. However, the extra escapes don't hurt and it is better to be in the habit of entering the escapes rather than not use one where it is needed. In other words, you are much more likely to have a problem that results from not having an escape when you needed one than having an escape when you should not have one.
- NOTE2:The above regular expression does not account for the possibility of having a wikitext sequence such as
[[Some page|name=john doe]]
within the template. This is not accounted for for two reasons: 1. It is an unlikely sequence to occur and I am not expecting you to run this as an unattended bot (i.e. a human should catch any such unlikely errors). 2. A bug in AWB currently makes it such that a regular expression to account for that possibility does not work under "Normal settings", but does work under both the "Advanced settings" and in the Regex Tester. — Makyen (talk) 23:52, 17 April 2014 (UTC)
- User:Makyen Is the greek version of Template:Infobox football biography but they are the same! Maybe is easiest to remove everything in in name parameter and then add | name= {{PAGENAME}}. I can do the second, but I can't to the first. Xaris333 (talk) 16:42, 15 April 2014 (UTC)
Regex tester
I am trying to piece together how Regexs work, based on the Help and the examples on this page. I am terrified of testing my ideas live on AWB, and hence live Wikipedia - surely there has to be a better way. I see mention of a Regex tester on this page, but no indication of what it is or where it might be found - is that available to normal editors?--Gronk Oz (talk) 10:36, 27 December 2015 (UTC)
- Never mind - I found it, under AWB's Tools menu. Sorry for the inconvenience; this will be brilliant for learning!--Gronk Oz (talk) 11:22, 27 December 2015 (UTC)
- @Gronk Oz: Another thing you can do is create a page in your userspace with several examples, and then run your regexes against them. Happy testing! GoingBatty (talk) 13:53, 27 December 2015 (UTC)
how to bold title in first line of the text
Hi, how can i bold title in first line of the text? for example
At foo article i want to do this
foo is a bar
with
'''foo''' is a bar
Yamaha5 (talk) 18:49, 20 October 2015 (UTC)
- @Yamaha5: AWB's general fixes should already bold the title in the first line of text. Do you have some examples where it doesn't? Thanks! GoingBatty (talk) 14:15, 27 December 2015 (UTC)
Replace certain internal links with interwiki links
Hello. I'm moving several pages from my wiki to a sister project and gonna replace the remained redlinks with interwiki. What commands should I use? (I'm not good with regex)
For example, I wanna change
[[Foo|some text]] [[Foo]]
to
[[:interwiki:Foo|some text]] [[:interwiki:Foo|Foo]]
I also have a .txt with a list of all pages that I want to replace; can I use it in the AWB or I have to set replacement rules for every link manually?
--Mizushima (01/11/16) — Preceding unsigned comment added by Mizusima (talk • contribs) 20:28, 11 January 2016 (UTC)
- @Mizushima: Let's pretend you had three pages that you wanted to replace: foo, bar, and fubar. You could then use the following:
\[\[(foo|bar|fubar)\|(.*?)\]\]
→[[:interwiki:$1|$2]]
\[\[(foo|bar|fubar)\]\]
→[[:interwiki:$1|$1]]
- Good luck! GoingBatty (talk) 03:39, 13 January 2016 (UTC)
how to find entries for an infobox that do not match an enumerated list
{{Infobox album}} lists an acceptable list of enumerated values for various parameters such as type = studio|demo|ep|live|greatest|remix|box|compilation|mixtape|soundtrack|film|cast|video|other. If it's not one of those items, I would like to add it to the list and then I can review and replace as required. How can I generate that regex? Walter Görlitz (talk) 01:39, 8 February 2016 (UTC)
Help with find and replace
I want to replace <small>(foobar)</small>
with {{c|foobar}}
, where “foobar” is any string of characters.
For example, <small>(1, 2, 3, 4, hello!)</small>
would be replaced with {{c|1, 2, 3, 4, hello!}}
.
I am not too experienced with advanced find and replace, therefore I need some help. Thank you.
―PapíDimmi (talk) 16:39, 30 May 2016 (UTC)
- @PapíDimmi I think replacing
<small>\((.*)\)<\/small>
with\{\{c\|$1\}\}
(with regex on) will do it. I haven't tested this in AWB, so make sure to check your edits! — crh 23 (Talk) 17:26, 30 May 2016 (UTC)- Thanks, but it did not work. It replaced
<small>(foobar)</small>
with\{\{c\|foobar\}\}
.
―PapíDimmi (talk) 17:32, 30 May 2016 (UTC)- @PapíDimmi Welp, silly mistake there: Use
{{c|$1}}
in the replace box instead, that should work. (Worked in notepad++, I should test with a less forgiving engine !) — crh 23 (Talk) 17:41, 30 May 2016 (UTC)- @Crh23: (Sorry for the rather late reply.) That works perfectly! Thank you.
―PapíDimmi (talk) 19:57, 30 May 2016 (UTC)
- @Crh23: (Sorry for the rather late reply.) That works perfectly! Thank you.
- @PapíDimmi Welp, silly mistake there: Use
- Thanks, but it did not work. It replaced
@Crh23: Actually, I have a problem.
It replaced <small>(''Foo Bar'')</small><br>foo <small>(''Bar Foo'')</small>
with {{c|''Foo Bar'')</small><br>foo <small>(''Bar Foo''}}
.
It should have replaced it with {{c|''Foo Bar''}}<br>foo {{c|''Bar Foo''}}
(I just replaced the text with “foo” and “bar.”)
I think this is because there was no space after </small>
.
―PapíDimmi (talk) 20:36, 30 May 2016 (UTC)
- Your regex match is being greedy. If you think about it, the match is right, just not what you wanted. You could try
.*?
(i.e. add a question mark after the asterix). Mr Stephen (talk) 20:45, 30 May 2016 (UTC)- I did not see your reply until now, because I got no notification (since you did not tag me). Anyway, this works perfectly! Thank you, Mr. Stephen and Crh23, for your help.
―PapíDimmi (talk) 02:39, 31 May 2016 (UTC)
- I did not see your reply until now, because I got no notification (since you did not tag me). Anyway, this works perfectly! Thank you, Mr. Stephen and Crh23, for your help.
I need some help with find and replace
I asked this a couple of days ago but have not yet received a response, therefore I will ask here as well.
I would like to replace this:
{{Series tabs |backcolor=Orange |altbackcolor=Orange |bordercolor=Blue |borderradius=6 |height= |maxwidth= |tab1=any string of characters |tab2=Original |tab3=Re-imagined }}
with this:
{{tab2|any string of characters}}
I.e., replacing the whole series tabs template with the tab2 template, only keeping a selected string of characters.
For example, it would replace this:
{{Series tabs |backcolor=Orange |altbackcolor=Orange |bordercolor=Blue |borderradius=6 |height= |maxwidth= |tab1=Foo1bar! |tab2=Original |tab3=Re-imagined }}
with this:
{{tab2|Foo1bar!}}
I tried numerous things but failed. I am not too experienced with RegEx therefore need some help.
Can anyone please help me with this? I would really appreciate it!
―PapíDimmi (talk) 02:50, 31 May 2016 (UTC)
- Use the regex tester in AWB (tools -> Regex tester). Paste the text to be searched in the obvious place and start building your regex in the "Find" box. Keep clicking the find button as you expand your regex. When you get to the bit you want to keep, throw a $1 into the replace box and alternate between the find & replace buttons. When the match fails or isn't right, start thinking. Your starter for free: escape the curly brackets and the pipe symbols, and put a tick in the SingleLine box. Mr Stephen (talk) 23:08, 31 May 2016 (UTC)
- @Mr Stephen: I like that you like to make me think as opposed to telling me outright, but it does not work for me. I cannot “start thinking,” as I have very little experience with RegEx. I have just recently started using AutoWikiBrowser.
- I tried doing what you told me to, but I do not know how I am supposed to do it correctly.
―PapíDimmi (talk) 00:19, 1 June 2016 (UTC)
- I tried doing what you told me to, but I do not know how I am supposed to do it correctly.
- Assuming you only want that specific template formatting to be replaced, a regex that I think works is replace
\{\{Series tabs\s\|backcolor=Orange\s\|altbackcolor=Orange\s\|bordercolor=Blue\s\|borderradius=6\s\|height=\s\|maxwidth=\s\|tab1=(.*)\s\|tab2=Original\s\|tab3=Re-imagined\s\}\}
with{{tab2|$1}}
. This will only match exactly what is in your examples, and move the characters after "tab1=" and before "|tab2=" into the new template. If you want it to match any invocation of {{Series tabs}} with a parameter of tab1, you would want to find\{\{Series tabs.*?\|tab1\s?=\s?(.*?)\s?\|.*?\}\}
instead. — crh 23 (Talk) 09:17, 1 June 2016 (UTC)- @Crh23: Hello. Thank you for your help, I really appreciate it. The first code (which only search for the series tabs with the specific parameters) worked, however, I would, in fact, like to match any invocation of
{{Series tabs}}
, but the second code you provided did not work.
―PapíDimmi (talk) 21:14, 1 June 2016 (UTC)- It works when I try it. I fear it will fail if the
tab1=
section is the last in the template. Mr Stephen (talk) 23:07, 1 June 2016 (UTC)
- It works when I try it. I fear it will fail if the
- @Crh23: Hello. Thank you for your help, I really appreciate it. The first code (which only search for the series tabs with the specific parameters) worked, however, I would, in fact, like to match any invocation of
- @Mr Stephen @Crh23: Here is what I did:
- Find:
?
- Replace:
{{tab2|$1}}
- Find:
- Then I made AutoWikiBrowser scan an article which contained this:
{{Series tabs
- |backcolor=Orange
- |altbackcolor=Orange
- |bordercolor=Blue
- |borderradius=6
- |height=
- |maxwidth=
- |tab1=foobar
- |tab2=Original
- |tab3=Re-imagined
}}
- …but it did not replace anything. I had only the “Regular expression” box ticked.
―PapíDimmi (talk) 01:48, 2 June 2016 (UTC)- No need for secrecy, which article? Mr Stephen (talk) 06:33, 2 June 2016 (UTC)
- @Mr Stephen: It does not matter which article; the bot scanned an article which contained the code I previously provided, and it replaced nothing; however, if I put the first code provided to me by Crh23, it will replace the series tabs with tab2. I do not know why, it does not matter how hard I try.
―PapíDimmi (talk) 07:04, 2 June 2016 (UTC)- @PapíDimmi: Whoops: forgot to mention that for the second one you need SingleLine ticked! Mr Stephen mentioned that the above regex won't work when
tab1
is the last parameter, that can be fixed by finding\{\{Series tabs.*?\|tab1\s?=\s?(.*?)(?:\s*\|.*?|\s*)\}\}
instead. — crh 23 (Talk) 11:57, 2 June 2016 (UTC)- P.S. If you want to see how that regex works, have a look at this website, which breaks it down by token. — crh 23 (Talk) 11:59, 2 June 2016 (UTC)
- @Crh23: Thank you so much for your help! If it is not too much trouble, could you help me with my last problem as well?
―PapíDimmi (talk) 20:50, 2 June 2016 (UTC)
- @Crh23: Thank you so much for your help! If it is not too much trouble, could you help me with my last problem as well?
- P.S. If you want to see how that regex works, have a look at this website, which breaks it down by token. — crh 23 (Talk) 11:59, 2 June 2016 (UTC)
- @PapíDimmi: Whoops: forgot to mention that for the second one you need SingleLine ticked! Mr Stephen mentioned that the above regex won't work when
- @Mr Stephen: It does not matter which article; the bot scanned an article which contained the code I previously provided, and it replaced nothing; however, if I put the first code provided to me by Crh23, it will replace the series tabs with tab2. I do not know why, it does not matter how hard I try.
- No need for secrecy, which article? Mr Stephen (talk) 06:33, 2 June 2016 (UTC)
- …but it did not replace anything. I had only the “Regular expression” box ticked.
Add spaces to headings
Hi!
I would like to replace ==Foobar==
with == Foobar ==
, where “Foobar” is any string of characters (aka any word/words, symbol/symbols, number/numbers, etc.).
Example:
Replace this:
==Amazing Header of 2016== This is some sort of section. Indeed, it is.
with this:
== Amazing Header of 2016 == This is some sort of section. Indeed, it is.
I would also like the same to apply to ===Foobar===
and ====Foobar====
.
―PapíDimmi (talk | contribs) 19:05, 15 June 2016 (UTC)
- Is this for the English WP? Mr Stephen (talk) 19:43, 15 June 2016 (UTC)
- @Mr Stephen: it's not - PapiDimmi doesn't have AWB rights on enwiki, and their previous edits aren't to enwiki. — crh 23 (Talk) 20:04, 15 June 2016 (UTC)
- @PapiDimmi: First, make sure this is desirable on the wiki you are working on — here on enwiki mass changing this would be forbidden, articles need only be consistent within themselves. If it is acceptable, try replacing
(\s)(=+)\s*(\S.*?\S)\s*\2(\s)
with$1$2 $3 $2$4
. — crh 23 (Talk) 20:04, 15 June 2016 (UTC)- Yes, it is desirable—in fact, I was told to.
―PapíDimmi (talk | contribs) 14:49, 16 June 2016 (UTC) - Nah, that won't work.
(\s)(=+)(\S.*?\S)\2(\s)
seems OK. Mr Stephen (talk) 21:29, 15 June 2016 (UTC)- Aren't we adding spaces? — crh 23 (Talk) 21:50, 15 June 2016 (UTC)
- Indeed we are, but what if they are already there? Mr Stephen (talk) 21:54, 15 June 2016 (UTC)
- I assume then we will leave as is? — crh 23 (Talk) 21:56, 15 June 2016 (UTC)
- Your regex will match several '=' followed by a space, as both '\S' and '.' match a '='. Mr Stephen (talk) 23:03, 15 June 2016 (UTC)
- Good point, but yours doesn't fix that: both
(\s)(=+)\s*(\S.*?\S)\s*\2(\s)
and(\s)(=+)(\S.*?\S)\2(\s)
match====
. That said yours may be slightly more useful if we want to fix headings that have too many spaces. With that in mind, I propose(\s)(=+)\s*([^\s=].*?[^\s=])\s*\2(\s)
. — crh 23 (Talk) 09:51, 16 June 2016 (UTC)- @Mr Stephen @Crh23: Thanks for your help! @Crh23: It seems to work nicely!
―PapíDimmi (talk | contribs) 14:49, 16 June 2016 (UTC)
- @Mr Stephen @Crh23: Thanks for your help! @Crh23: It seems to work nicely!
- Good point, but yours doesn't fix that: both
- Your regex will match several '=' followed by a space, as both '\S' and '.' match a '='. Mr Stephen (talk) 23:03, 15 June 2016 (UTC)
- I assume then we will leave as is? — crh 23 (Talk) 21:56, 15 June 2016 (UTC)
- Indeed we are, but what if they are already there? Mr Stephen (talk) 21:54, 15 June 2016 (UTC)
- Aren't we adding spaces? — crh 23 (Talk) 21:50, 15 June 2016 (UTC)
- Yes, it is desirable—in fact, I was told to.
Switch order of two sections
Is there a way I could switch the order of two sections?
For example, I would like to find this:
==Section 1== *[[Foo Bar]] *[[Lorem Ipsum]] *[[Bar Foo]] ==Section 2== *[[Dolor sit amet]] *[[Xyzzy]]
and replace it with this:
==Section 2== *[[Dolor sit amet]] *[[Xyzzy]] ==Section 1== *[[Foo Bar]] *[[Lorem Ipsum]] *[[Bar Foo]]
I would like to switch the order of two sections, keeping the name of the sections and their content, simply switching the order.
I have tried, but I cannot get it to work. I tried putting .{1,}
in the find, below the sections, and $1
and $2
in the replace, but it did not work when I tested it. I also tested with (.*?)
, but I cannot get it to work. I have little experience with RegEx and would appreciate some help.
―PapíDimmi (talk | contribs) 00:27, 1 June 2016 (UTC)
- @PapíDimmi: Can you clarify exactly what you want to happen: is it sections of two specific names you want swapped? Will they already be in a particular order? Will they be adjacent? If you could be specific about the use for this regex, that would really help. — crh 23 (Talk) 20:52, 2 June 2016 (UTC)
- @Crh23: I want to switch the order of two specific sections in articles.
- If I am going to be specific, I want the “See also” section, if it is above the “Appearances” section, to move below the “Appearances” section.
- For example, I would want to switch this:
- with this:
- I.e., I would simply like to move the “See also” section below the “Appearances” section on pages where the “See also” section is above the “Appearances” section. If the “See also” section is already below the “Appearances” section, no changes should be made.
―PapíDimmi (talk | contribs) 21:02, 2 June 2016 (UTC)- OK, I think I've got something that works. You'll need SingleLine ticked. Replace
\s?(== ?See [a|A]lso ?==\s+.*?)\s?(== ?Appearances ?==\s*.*?)\s?(=|\Z)
with\n$2\n$1\n$3
. To be precise, this takes the Appearances section (iff it is below the See also section) and puts it immediately above the see also section: if the sections are not adjacent it may cause whitespace problems, not sure. — crh 23 (Talk) 21:33, 2 June 2016 (UTC)- @Crh23: Thank you, that almost works; however, it removes the space. I would like it to keep the space in-between the two sections.
- OK, I think I've got something that works. You'll need SingleLine ticked. Replace
- I.e., I would simply like to move the “See also” section below the “Appearances” section on pages where the “See also” section is above the “Appearances” section. If the “See also” section is already below the “Appearances” section, no changes should be made.
- E.g., it replaced this:
==See also== *[[lorem]] *[[ipsum]] *[[xyzzy]] ==Appearances== *[[foo]] *[[bar]]
- with this:
==Appearances== *[[foo]] *[[bar]] ==See also== *[[lorem]] *[[ipsum]] *[[xyzzy]]
―PapíDimmi (talk | contribs) 00:11, 3 June 2016 (UTC)
- @PapíDimmi: That was a little tricky to figure out, but I think I've got it. Find
(== ?See [a|A]lso ?==\s+.*?)(\s*)(== ?Appearances ?==\s+.*?)(\s*(?:=|\Z))
and replace with$3$2$1$4
, again with SingleLine ticked. What this does (I hope!) is swap the sections around, ignoring whitespace at the end, keeping the whitespace between them in place. — crh 23 (Talk) 08:45, 3 June 2016 (UTC)- @Crh23: That works superbly! Thank you for all the help you have given me!
―PapíDimmi (talk | contribs) 10:13, 3 June 2016 (UTC)- @Crh23: Hello. I, unfortunately, encountered an error. In articles with the template Interlang, it removes Interlang’s parameters and puts them below the “See also” section. Here is a screenshot. As you can see in the screenshot, it moved the “See also” into the Interlang template, making it a parameter of the template; it does not show up on the page and nor does the Interlang template’s actual parameters. Could you please help me keep this error from happening? Thank you.
―PapíDimmi (talk | contribs) 20:41, 4 June 2016 (UTC) - I also encountered AutoWikiBrowser move reference names and templates below the “See also” and “Appearances” sections. If you cannot fix these errors, that is fine; I will stop using the RegEx code. However, if you can, I would really appreciate it.
―PapíDimmi (talk | contribs) 21:14, 4 June 2016 (UTC)- @PapíDimmi: Using
(== ?See [a|A]lso ?==\s+.*?)(\s*)(== ?Appearances ?==\s+.*?)(\s*(?:==|\Z))
I think fixes those errors: the problem is that the regex was treating = as the start of a new section (I didn't account for its use in templates, now it only treats == as a new section. There still may be some situations where the find and replace will produce errors (use of<nowiki>...</nowiki>
, use of single equals headings, etc.): these are unavoidable without making it significantly more complicated. — crh 23 (Talk) 10:14, 5 June 2016 (UTC)- Thanks, I will try that.
―PapíDimmi (talk | contribs) 21:52, 5 June 2016 (UTC) - @Crh23: It seems to work nicely, except it moves the “See also” section below the Interlang template. In an article, there was a See also section, Appearances section, and an Interlang template. Once AutoWikiBrowser edited it, there was an Appearances section, Interlang template, and See also section. The Interlang template should be at the bottom and not in the middle of the two sections. Is there a way to fix this? Sorry if I am asking for too much, but I would be really glad if you could help me with this, and hopefully there would be no more problems with it.
―PapíDimmi (talk | contribs) 03:47, 7 June 2016 (UTC)
- Thanks, I will try that.
- @PapíDimmi: Using
- @Crh23: Hello. I, unfortunately, encountered an error. In articles with the template Interlang, it removes Interlang’s parameters and puts them below the “See also” section. Here is a screenshot. As you can see in the screenshot, it moved the “See also” into the Interlang template, making it a parameter of the template; it does not show up on the page and nor does the Interlang template’s actual parameters. Could you please help me keep this error from happening? Thank you.
- @Crh23: That works superbly! Thank you for all the help you have given me!
- @PapíDimmi: That was a little tricky to figure out, but I think I've got it. Find
- (←) @PapíDimmi: What is the form of the Interlang template, is it {{Interlang}}? If so,
(== ?See [a|A]lso ?==\s+.*?)(\s*)(== ?Appearances ?==\s+.*?)(\s*(?:==|\Z|\{\{[Ii]nterlang\}\}))
should work — it treats the interlang template as another way to end the appearances section. — crh 23 (Talk) 13:23, 7 June 2016 (UTC)- Thanks. I will try that.
―PapíDimmi (talk | contribs) 15:55, 7 June 2016 (UTC) - @Crh23: Hello. Unfortunately, it does not work.
- Thanks. I will try that.
- It replaced this:
==See also== *[[Foo Bar]] ==Appearances== *[[Lorem ipsum]] {{co}} {{Interlang | es = Foobar }}
- with this:
==Appearances== *[[Lorem ipsum]] {{co}} {{Interlang | es = Foobar }} ==See also== *[[Foo Bar]]
- I tested without the
{{co}}
template, it did the same thing, so that template is not the cause. I want the Interlang template to be at the bottom, where it already was.
―PapíDimmi (talk | contribs) 00:54, 9 June 2016 (UTC)- Right, so the template is not just of the form {{Interlang}}.
(== ?See [a|A]lso ?==\s+.*?)(\s*)(== ?Appearances ?==\s+.*?)(\s*(?:==|\Z|\{\{[Ii]nterlang.*?\}\}))
will fix that I think, not tested much though.— crh 23 (Talk) 10:08, 9 June 2016 (UTC)- Oh, my apologies; I forgot to mention that {{Interlang}} has parameters (I thought that you already knew that). Thank you for helping me. I will try the code provided and get back to you if it works or does not.
―PapíDimmi (talk | contribs) 20:22, 9 June 2016 (UTC)- We don't use it on enwiki - it's all done through wikidata. I'm not sure why the template exists here actually. The only link to it is this discussion.
— Preceding unsigned comment added by Crh23 (talk • contribs) 09:52, 10 June 2016 (UTC) - @Crh23: I found a problem.
- We don't use it on enwiki - it's all done through wikidata. I'm not sure why the template exists here actually. The only link to it is this discussion.
- Oh, my apologies; I forgot to mention that {{Interlang}} has parameters (I thought that you already knew that). Thank you for helping me. I will try the code provided and get back to you if it works or does not.
- Right, so the template is not just of the form {{Interlang}}.
- I tested without the
- It replaced this:
==See also== *Bar ==Appearances== *Foo [[Category:Foobar]]
- with this:
==Appearances== *Foo [[Category:Foobar]] ==See also== *Bar
- I want it to replace it with this:
==Appearances== *Foo ==See also== *Bar [[Category:Foobar]]
- I would be very happy if you could help me with this! Thank you.
―PapíDimmi (talk | contribs) 17:10, 12 June 2016 (UTC)- Added categories as another way to end the last section,
(== ?See [a|A]lso ?==\s+.*?)(\s*)(== ?Appearances ?==\s+.*?)(\s*(?:==|\Z|\{\{[Ii]nterlang.*?\}\}|\[\[[cC]ategory:))
, not tested, other settings as before. — crh 23 (Talk) 21:55, 15 June 2016 (UTC)- @Crh23: Thank you! I will try that.
―PapíDimmi (talk | contribs) 14:49, 16 June 2016 (UTC)
- @Crh23: Thank you! I will try that.
- Added categories as another way to end the last section,
- I would be very happy if you could help me with this! Thank you.
@Crh23: It did not work as intended.
It replaced this:
==See also== *Bar ==Appearances== *Foo [[Category:Foobar]]
with this:
==Appearances== *Foo ==See also== *Bar [[Category:Foobar]]
There should be a space in-between the sections, like this:
==Appearances== *Foo ==See also== *Bar [[Category:Foobar]]
Could you help me fix that? Thank you.
―PapíDimmi (talk | contribs) 05:20, 19 June 2016 (UTC)
- @PapíDimmi: that problem was in the original text, so was transferred to the new text. The best way to fix this is a second regex, which will insert a blank line between all sections that don't have one. Find
(?<=[^\n\r])(\n)(=+)([^=\n]*?)\2(\n)
and replace with\n\n$2$3$2\n
(not tested much). — crh 23 (Talk) 08:22, 19 June 2016 (UTC)- That works. Thank you!
―PapíDimmi (talk | contribs) 08:24, 19 June 2016 (UTC)- I discovered a little problem: I do not want it to insert a space after an empty section.
- That works. Thank you!
- E.g., it replaces this:
==Foo== ===Bar=== Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
- with this:
==Foo== ===Bar=== Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
- I want there to be spaces in-between sections but not sections which are empty and are followed by another section instead. Therefore, I do not want it to replace the above example text with anything. Is there a workaround for this? Thank you.
―PapíDimmi (talk | contribs) 09:32, 19 June 2016 (UTC)- @PapíDimmi: Easy fix:
(?<=[^\n\r=])(\n)(=+)([^=\n]*?)\2(\n)
. — crh 23 (Talk) 13:15, 19 June 2016 (UTC)- That works. Thank you!
―PapíDimmi (talk | contribs) 13:23, 19 June 2016 (UTC)
- That works. Thank you!
- @PapíDimmi: Easy fix:
- I want there to be spaces in-between sections but not sections which are empty and are followed by another section instead. Therefore, I do not want it to replace the above example text with anything. Is there a workaround for this? Thank you.
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)
- 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)- (My apologies for the late reply.) That works perfectly. Thank you!
―PapíDimmi (talk | contribs) 15:58, 4 July 2016 (UTC)
- (My apologies for the late reply.) That works perfectly. Thank you!
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 (talk • contributions) 04:39, 29 June 2016 (UTC)
- 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)
- What's the context? I assume this is within a particular template, which? — crh 23 (Talk) 09:44, 29 June 2016 (UTC)
- It is for Commons:Template:Information. Thanks, OSX (talk • contributions) 12:03, 29 June 2016 (UTC)
- Will the options always be adjacent? — crh 23 (Talk) 12:47, 29 June 2016 (UTC)
- Yes. OSX (talk • contributions) 13:06, 29 June 2016 (UTC)
- 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)
- Find
- 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)
- 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 (talk • contributions) 14:24, 29 June 2016 (UTC)
- Thanks for the code. For me though, it does not work. I have copied your "find" code into the "find" field and
- Do you have Regex ticked too? — crh 23 (Talk) 14:42, 29 June 2016 (UTC)
- I do now and that fixed it! Thank you very much for your help :) OSX (talk • contributions) 14:50, 29 June 2016 (UTC)
- 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)
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)
- 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)
- 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)
- 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.
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)
- 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)- 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)
- 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.
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)
- Captured groups can be backreferenced in the Find string using a backslash followed by the number:
(\d+)x\1px
→$1px
. Note that340x340px
and340px
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)- Thank you!
―PapíDimmi (talk | contribs) 09:36, 10 July 2016 (UTC)
- Thank you!
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)
- You'll need two separate regexes. For example,
\[\[Wikipedia:([^\[\]\|]+)\|([^\[\]\|]+)\]\]
→{{w|$1|$2}}
to change all links to templates, followed by\{\{w\|([^\[\]\|]+)\|\1\}\}
→{{w|$1}}
to remove the second parameter if link and label are the same. Case differences such as{{w|Video game|video game}}
can be matched by not marking the second as case-sensitive, but it doesn't seem possible to make only the first character case-insensitive, like Wikipedia titles. SiBr4 (talk) 18:26, 16 September 2016 (UTC)
- @SiBr4: That works. Thank you!
―PapíDimmi (talk | contribs) 02:09, 17 September 2016 (UTC)
Problem with find and replace capture
I can't seem to get the Regex capture working. In AWB Regex Tester, I tested
^(\|.*area_total_km2\s+=).*
to find a parameter of infobox settlement:
| area_total_km2 = 169.75
The replacement I used was
\1 {{PH wikidata|area}}
with the intended result to give
| area_total_km2 = {{PH wikidata|area}}
But the result AWB gave was erroneous:
\1 {{PH wikidata|area}}
Both Multiline and ExplicitCapture settings are checked. Is there something wrong with the settings or syntax? I tested it on Notepad++ and the replacement works as intended. Sanglahi86 (talk) 13:42, 13 October 2016 (UTC)
- The code for backreferences in the "Replace" string is
$1
, not\1
. Backreferences in the "Find" string do use the latter form. SiBr4 (talk) 19:53, 13 October 2016 (UTC)
- Thank you very much for the info. Sanglahi86 (talk) 06:15, 14 October 2016 (UTC)