Wikipedia talk:AutoWikiBrowser/Find and replace
![]() | This is the talk page for Wikipedia:AutoWikiBrowser/Find and replace This is a good place to ask for help with find and replace operation in AWB, to discuss Wikipedia:AutoWikiBrowser/Find and replace or AWB's find and replace functionality. |
Index
|
|
|
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)
Ignore "|url=" and "|title=" of citation templates?
Find and replace offers one the ability to ignore the entirety of "templates, refs, link targets, and headings", however, I wanted to know if it was possible to only ignore the not-to-be-changed parameters in citation templates (|url= and |title= as prime examples), but still change interwiki link targets, also within citation templates (e.g. in the |website= parameter). Lordtobi (✉) 14:11, 25 February 2018 (UTC)
I have a table with 'Find', and 'Replace with' fields, is there a way to import this into 'AutoWikiBrowser'?
Hi all, I have a table with 'Find', and 'Replace with' fields, is there a way to import this into 'AutoWikiBrowser'? Best regards DynamoDegsy (talk) 13:21, 16 March 2018 (UTC)
- Not easily. You can save your settings in an XML file. You can try by adding one of your entries and saving it, then looking at that XML file. If you think you can convert your table to that format, you're set. There are no tools that I know of that can do this. Walter Görlitz (talk) 14:31, 16 March 2018 (UTC)
Replace uppercase by lowercase
Hi,
Is is possible to replace a string in uppercase by the same in lowercase?
For the context, on Wikisource the OCR sometimes put all caps words who need to be convert in small caps (lowercase inside the template {{sc}}). I found the syntaxe ([A-Z])([A-Z]*) -> $1\L$2 online but it doesn't work :( Any idea?