User:Zappernapper/AWB convert

Okay, step 1 is to read through Regular expressions, and the relevant manual page.

Step 2: Open up AWB and the advanced Find and Replace settings.

Step 3: Creating rules and subrules
 * It's important to have these rules processed in the same order listed here to avoid conflicts with AWB trying to apply convert multiple times. Also, these are ALL regular expressions, so you need to be sure that the option IS ALWAYS checked in the bottom of the dialog box, and the option for "Case sensitive" IS NEVER checked.

Remember: False positives can and WILL happen, check EVERY edit.

Rule 1
convert cannot handle the HTML entities that create dashes, they must be entered literally
 * New Rule: "remove ndash and mdash"
 * Find:
 *  ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(&amp;ndash;|&amp;mdash;|—)(\s|&amp;nbsp;)?([0-9]+\.?[0-9]*)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  $1-$5 $7 

Rule 2
''convert cannot handle numbers written as text, they must be converted. Most editors only write out the numbers 1-10.''
 * New Rule: "Text to numbers"
 * New Subule: "one"
 * Find:
 *  \b(a(?:n)?|an|one)\b(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b((centi|kilo|milli)?met(er|re)?|kilo|(kilo|milli)?gram(me)?|inch|mile|foot|pound|ounce)\b 
 * Replace:
 *  1$2$3$4$5 
 * New Subrule: "two"
 * Find:
 *  two(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  2$1$2$3$4 
 * '''Follow the example from Subrule "two" for "three"-"nine", creating a "ten" is optional. If you're unsure what to change, see the below examples.


 * New Subrule: "three"
 * Find:
 *  three(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  3$1$2$3$4 
 * New Subrule: "four"
 * Find:
 *  four(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  4$1$2$3$4 
 * New Subrule: "five"
 * Find:
 *  five(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  5$1$2$3$4 
 * New Subrule: "six"
 * Find:
 *  six(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  6$1$2$3$4 
 * New Subrule: "seven"
 * Find:
 *  seven(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  7$1$2$3$4 
 * New Subrule: "eight"
 * Find:
 *  eight(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  8$1$2$3$4 
 * New Subrule: "nine"
 * Find:
 *  nine(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?\b(cm|km|mm|(centi|kilo|milli)?m(et(er|re)(s)?)?|kg|mg|kilo(s)?|(kilo|milli)?g(ram(me)?(s)?)?|in(ch(es)?)?|mi(les?)?|ft|feet|foot|lb|lbs|pound(s)?|oz|ounce(s)?)\b 
 * Replace:
 *  9$1$2$3$4 

Rule 3
convert only accepts the abbreviated versions of measurments (e.g. ft, not feet).
 * New Rule: "Longhand to short"
 * New subrule: "convert cm"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?(centimeter(s)?)
 * Replace:
 * ''' $1$3cm
 * New subrule: "convert in"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?inch(es)?
 * Replace:
 * ''' $1$3in
 * New subrule: "convert km"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?kilomet(er|re)(s)?
 * Replace:
 * ''' $1$3km
 * New subrule: "convert m"
 * Find:
 * ''' ([0-9]+.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?met(er|re)(s)?
 * Replace:
 * ''' $1$3m
 * New subrule: "convert mm"
 * Find:
 * ''' ([0-9]+.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?millimet(er|re)(s)?
 * Replace:
 * ''' $1$3mm
 * New subrule: "convert ft"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?(feet|foot)
 * Replace:
 * ''' $1$3ft
 * New subrule: "convert mi"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?mile(s)?
 * Replace:
 * ''' $1$3mi
 * New subrule: "convert kg"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?kilo(gram(me)?)?(s)?
 * Replace:
 * ''' $1$3kg
 * New subrule: "convert g"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?gram(me)?(s)?
 * Replace:
 * ''' $1$3g
 * New subrule: "convert lb"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?(lbs|pound)(s)?
 * Replace:
 * ''' $1$3lb
 * New subrule: "convert mg"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?milligram(me)?(s)?
 * Replace:
 * ''' $1$3mg
 * New subrule: "convert oz"
 * Find:
 * ''' ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(-)?(\s|&amp;nbsp;)?ounce(s)?
 * Replace:
 * ''' $1$3oz

Rule four
Now convert is ready to process the article.
 * First convert needs to be applied to measurement ranges (e.g. 2-4 mi).
 * New subrule: "convert 2"
 * Find:
 *  ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(to|-|and|by|x)(\s|&amp;nbsp;)?([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b(\s|&amp;nbsp;)?(\(([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(((c|k|m)?(m|g|i)n?|ft|lb|oz)\b)?(\s|&amp;nbsp;)?(to|-|and)?(\s|&amp;nbsp;)?([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?(((c|k|m)?(m|g|i)n?|ft|lb|oz)\b)?\)?)? 
 * Replace:
 *  $1 $3 
 * Now we can apply convert to measurements with handwritten conversions, using the supplied output conversion instead of the default one (e.g. 3 in will be written as 3 in instead of 3 in which would default to converting inches to centimeters)
 * New subrule: "convert"
 * Find:
 *  ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b(\s|&amp;nbsp;)?\(([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b\) 
 * Replace:
 *  $1 $3 
 * The next conversions to be applied are those without handwritten conversions, for these we let convert decide what's best.
 * New subrule: "force convert"
 * Find:
 *  ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b 
 * Replace:
 *  $1 $3 
 * The final step is to convert adjective forms of measurements (e.g. a 10-foot pole).
 * New subrule: "adj convert"
 * Find:
 *  ([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?-(\s|&amp;nbsp;)?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b((\s|&amp;nbsp;)?\(([0-9]+\.?[0-9]*)(\s|&amp;nbsp;)?-?(\s|&amp;nbsp;)?((c|k|m)?(m|g|i)n?|ft|lb|oz)\b\))? 
 * Replace:
 *  $1 $4