User:Chris the speller/regular

From Wikipedia, the free encyclopedia

Regular expressions useful with WikEd[edit]

Each example has a line to put into the search box, followed by one or more lines (choose one) to put into the replacement box.
  • For the search box, take all the non-blank text, avoiding preceding or trailing blanks (\x20 is used instead of blanks).
  • For the replacement box, take all characters that appear between ++ and ++, as the preceding or trailing blanks may be important.

Change "3 ft tall" to use the convert template
also "2 ft wide" and so on. If converting to other than meters, change parameter 3 in the replacement text.
It also finds "3-ft tall", "3 ft tall", etc., and the search may yield false positives.
([0123456789,.]+)[ ]{0,6}-{0,1}\x20{0,1}(ft)-{0,1}\x20{0,1}([hig]{0,4}[wide]{0,4}[long]{0,4}[tal]{0,4}[dep]{0,4}[thick]{0,5})
++{{convert|$1|$2|m|abbr=on|adj=mid|$3}}++     changes "it is 3 ft tall" to "it is 3 ft tall (0.91 m)"
++{{convert|$1|$2|m|adj=mid|-$3}}++     changes "the 3 ft tall statue" to "the 3-foot-tall (0.91 m) statue"
You may then also want to move " statue" into the template following "tall", to produce "the 3-foot-tall statue (0.91 m)".

Swap two words (position the insertion point just before the two words before searching)
(\S+)(\x20)(\S+)
++$3$2$1++     Change "apples rotten" to "rotten apples"

Remove duplicated word
(\x20)(\w+)\x20\2
++$1$2++     Change "Stop that that thief!" to "Stop that thief!"

Find unspaced comma, period, question mark, etc.
([,\.\?\;\)\:])(\w)
++$1 $2++     insert the trailing blank. Avoid adding spaces to URLs!