Pybot Wiki
Advertisement

This page describes a bit of regex. It must be used within a script or user-fix.

Removing a pipe at end of line in infobox
Creator: CzechOut
What it does: Removes stray pipes at end of a line in an infobox
Complexity: moderate

Removing a pipe at end of line in infobox is a bit of regex that will help you remove pipes (|) that may be at the end of a line.

Let's say that you had a prolific editor who was working with templates she had created offline. But she added a stray pipe at the end of a line, like so:

|name = Sam Smith |
|age  = 34
|sex  = unspecified

And because she's replicated this error hundreds of times across the site, it'll be a pain to manually remove this single pipe. This little bit of code searches out the precise line ending in a pipe and removes it.

It is typically used with the replace.py script.

Code[]

python pwb.py replace.py -regex -pt:1 
-summary:"INFOBOX CLEANUP: Getting rid of appending pipe in an infobox line" 
'\|( *)\r' '\1' -start:!

Explanation[]

This regex matches lines that end with a pipe, an optional amount of spaces from 0 to infinity, and a carriage return. It then replaces the match of everything it's found with just the number of spaces it's found.

\| means find a pipe (the slash escapes the pipe, letting the bot know we're looking for a literal pipe)
( *) means find any number of spaces, if they even exist
\r means find a carriage return

Known limitations[]

This situation can also occur in tables that are set up using wikitext. Depending on how many tables are found on your wiki, this could be a problem.

For this reason it is recommended that you do not run this in automatic mode.

Why bother?[]

You may well wonder why we should even bother getting rid of the stray pipe. After all, a stray pipe in this situation is essentially harmless — the infobox will still display properly if it encounters an extraneous pipe.

But it can be detrimental to other bot runs ago encounter a pipe in an unexpected location nd probably should be eliminated as a matter of "good grooming".

Advertisement