Article

October 17, 2021

Find something and replace it with something else

Hi, AWB question. I want to replace a defaultsort with something further up as a string in an article. I actually want to leave the string where I get the data from, but only replace it to replace something else. I have now tried this: find "code \(.*?)\<" replace "code \$1\<"find \{\{DEFAULTSORT\:(.*?)\}\} replace \{\{DEFAULTSORT\:$1\}\} (That there is code twice is correct, with that I can uniquely identify the string). AWB does not trigger. Now my regex syntax may be faltering, but is this the way to work anyway? (It's about the Category:Regional Indicator Symbol, but if this works I can do a bit more with this). Milliped (talk) Oct 3, 2021 12:58 PM (CEST) I don't know what kind of language this is, but it seems that through the find the pattern is stored in parentheses () in a buffer $1. This buffer is then used as the replacement value during the replace. Usually this can only be done in one and the same command. Suppose I have the string "a12 b12 c12" and I only want to replace the 12 in b12 with 21, then you get via the Unix/Linux command sedL sed -e "s/\(b\)12/\121/". \( \) here has the same meaning as I presume above means (), and the same for \1 and $1. If this is the idea then the combination find/replace above will have no effect (if it would work at all) as the found() in find is replaced by itself $1 at the replace. --3 Oct 2021 13:43 (CEST) Hi, the language is regex (no idea which dialect AWB uses, I'm somewhat familiar with PCRE). So the idea is to use that buffer somewhere else. Milliped (talk) Oct 3, 2021 13:47 (CEST)Regex (regular expression) means nothing to me. In the example with sed (stream editor) a regex is also used. All those search and replace constructions via a regex could well have their origin in sed. Where do you use these commands? --Sb008 (consultation) Oct 3, 2021 13:53 (CEST) In AWB. In the search & replace command I use the "normal settings" and I check regex. (So ​​I don't know which dialect regex uses). Milliped (talk) Oct 3, 2021 13:56 (CEST) In AWB I use the following regex guide: en:Wikipedia:AutoWikiBrowser/Regular expression. My guess is that the first $1 will pick up the result of the first find, and the second that of the second. So: on balance no change. But... I'm not a very experienced AWB user either. Why don't you put it to Edodero? Pommée (consultation) 3 Oct 2021 14:14 (CEST) Or at bdijkstra →bertux 3 Oct 2021 14:33 (CEST) (na bwc) I don't know AWB so I can't help you further. (I have already requested permission to use it.) With a search and replace it is generally not possible to replace pattern x with a pattern y that will only be defined in the future (further in the text). This is actually only possible when the text is run through 2x or by running through the text backwards when y occurs by definition after x in the text. However, the order of x and y is not fixed in a random case, so the text should always be run through 2x. In the 1st run the find is used, where the result is e.g. placed in a variable. In the 2nd pass, replace then uses the value of the variable for the actual replace. By default, a replacement via a regex does not use ('n) variable(s) but ('n) buffer(s). Buffers cease to exist upon termination of a command and cannot be transferred between 2 commands. It could well be that it is possible in AWB, because an extra layer has been built in to make this possible, e.g. via variables. However, this is not obvious because if one were to give only search commands, say 1000 search commands, there would be 1000 defined variables. This too can be solved

INSERT INTO `wiki_article`(`id`, `article_id`, `title`, `article`, `img_url`) VALUES ('NULL()','Help:Helpdesk','','This too can be solved','')