Jump to content

User:TomTheHand/Unit tests for AWB regexes/Power

From Wikipedia, the free encyclopedia

This section contains regular expressions for formatting units of power.

Replace horsepower with {{convert}}

[edit]

Similar to the expressions for nautical miles, this task requires several rules. The first strips commas and spaces from large numbers of horsepower. The second converts abbreviated uses of horsepower. The third converts unabbreviated noun phrases. The fourth converts unabbreviated adjectival phrases. They should not be set up as sub-rules, because then they would only run when we've stripped commas or spaces; we may be dealing with small numbers, so there were no commas to strip, or the article may have simply been written without commas.

Remove commas

[edit]
Description
Remove commas from quantities of horsepower.
Find
\b(?<=\d+)(\s|&nbsp;|,)(?=\d{3,3}(?:(?:\s|&nbsp;|,)\d{3,3})*(\.\d*)?(?:\s|&nbsp;|-)?(?:(?:shaft|indicated|brake)(?:\s|&nbsp;|-)?)?(?:horse(?:\s|&nbsp;|-)?power|(?:s|i|b)?hp)\b)
Replace with
(leave this field blank!)
Regular expression? Case sensitive?
Y N
Text this regex should modify: Intended result:
  1. 15,000 hp
  2. 150,000 shp
  3. 1,500.8 ihp
  4. 11,000 bhp (8,200 kW)
  1. 15000 hp
  2. 150000 shp
  3. 1500.8 ihp
  4. 11000 bhp (8,200 kW)


Convert abbreviated phrases

[edit]
Description
Use Convert template on abbreviated horsepower figures
Find
\b(?<![,\.$])(\d+(?:\.\d+)?)(?:\s|&nbsp;|-)?(b|i|s)?hp\b(\s?\(?\d{1,3}(?:,?\d{3,3})*(\.\d*)?(?:\s|&nbsp;)?(?:watts?|W|kilowatts?|kW|megawatts?|MW)\)?)?
Replace with
{{convert|$1|$2hp|abbr=on}}
Regular expression? Case sensitive?
Y N
Text this regex should modify: Intended result:
  1. 50 hp
  2. 50hp
  3. 50-hp
  4. 50 hp
  5. 50 bhp
  6. 50bhp
  7. 50-bhp
  8. 50 bhp
  9. 50 ihp
  10. 50ihp
  11. 50-ihp
  12. 50 ihp
  13. 50 shp
  14. 50shp
  15. 50-shp
  16. 50 shp
  17. 50 hp (37 kW)
  18. 50hp (37 kW)
  19. 50-hp (37 kW)
  20. 50 hp (37 kW)
  1. 50 hp (37 kW)
  2. 50 hp (37 kW)
  3. 50 hp (37 kW)
  4. 50 hp (37 kW)
  5. 50 bhp (37 kW)
  6. 50 bhp (37 kW)
  7. 50 bhp (37 kW)
  8. 50 bhp (37 kW)
  9. 50 ihp (37 kW)
  10. 50 ihp (37 kW)
  11. 50 ihp (37 kW)
  12. 50 ihp (37 kW)
  13. 50 shp (37 kW)
  14. 50 shp (37 kW)
  15. 50 shp (37 kW)
  16. 50 shp (37 kW)
  17. 50 hp (37 kW)
  18. 50 hp (37 kW)
  19. 50 hp (37 kW)
  20. 50 hp (37 kW)
Text this regex should not modify:
  1. 50 hps
  2. 50hps
  3. 50-hps
  4. 50 hps

Convert unabbreviated noun phrases

[edit]
Description
Use Convert template on unabbreviated horsepower figures
Find
\b(?<![,\.$])(\d+(?:\.\d+)?)(?:\s| )?(b|i|s)?(?:rake|ndicated|haft)?(?:\s| )?horse(?:\s| |-)?powers?\b(\s?\(?\d{1,3}(?:,?\d{3,3})*(\.\d*)?(?:\s| )?(?:watts?|W|kilowatts?|kW|megawatts?|MW)\)?)?
Replace with
{{convert|$1|$2hp}}$3
Regular expression? Case sensitive?
Y N
Text this regex should modify: Intended result:
  1. 50 horse power
  2. 50horsepower
  3. 50 horse-power
  4. 50 brake horse power
  5. 50brakehorsepower
  6. 50 brake horse-power
  7. 50 indicated horse power
  8. 50indicatedhorsepower
  9. 50 indicated horse-power
  10. 50 shaft horse power
  11. 50shafthorsepower
  12. 50 shaft horse-power
  13. 50 horsepowers
  14. 50horsepowers
  15. 50 horsepowers
  16. 50 horsepower (37 kW)
  17. 50horsepower (37 kW)
  18. 50 horse-power (37 kW)
  1. 50 horsepower (37 kW)
  2. 50 horsepower (37 kW)
  3. 50 horsepower (37 kW)
  4. 50 brake horsepower (37 kW)
  5. 50 brake horsepower (37 kW)
  6. 50 brake horsepower (37 kW)
  7. 50 indicated horsepower (37 kW)
  8. 50 indicated horsepower (37 kW)
  9. 50 indicated horsepower (37 kW)
  10. 50 shaft horsepower (37 kW)
  11. 50 shaft horsepower (37 kW)
  12. 50 shaft horsepower (37 kW)
  13. 50 horsepower (37 kW)
  14. 50 horsepower (37 kW)
  15. 50 horsepower (37 kW)
  16. 50 horsepower (37 kW)
  17. 50 horsepower (37 kW)
  18. 50 horsepower (37 kW)

Convert unabbreviated adjectival phrases

[edit]
Description
Use Convert template on unabbreviated adjectival horsepower figures
Find
\b(?<![,\.$])(\d+(?:\.\d+)?)-(b|i|s)?(?:rake|ndicated|haft)?(?:\s| |-)?horse(?:\s| |-)?powers?\b(\s?\(?\d{1,3}(?:,?\d{3,3})*(\.\d*)?(?:\s| )?(?:watts?|W|kilowatts?|kW|megawatts?|MW)\)?)?
Replace with
{{convert|$1|$2hp|adj=on}}
Regular expression? Case sensitive?
Y N
Text this regex should modify: Intended result:
  1. 50-horse power
  2. 50-horsepower
  3. 50-horse-power
  4. 50-brake horse power
  5. 50-brakehorsepower
  6. 50-brake-horsepower
  7. 50-brake-horse-power
  8. 50-indicated horse power
  9. 50-indicatedhorsepower
  10. 50-indicated-horsepower
  11. 50-indicated-horse-power
  12. 50-shaft horse power
  13. 50-shafthorsepower
  14. 50-shaft-horsepower
  15. 50-shaft-horse-power
  16. 50-horsepowers
  17. 50-horsepower (37 kW)
  1. 50-horsepower (37 kW)
  2. 50-horsepower (37 kW)
  3. 50-horsepower (37 kW)
  4. 50-brake-horsepower (37 kW)
  5. 50-brake-horsepower (37 kW)
  6. 50-brake-horsepower (37 kW)
  7. 50-brake-horsepower (37 kW)
  8. 50-indicated-horsepower (37 kW)
  9. 50-indicated-horsepower (37 kW)
  10. 50-indicated-horsepower (37 kW)
  11. 50-indicated-horsepower (37 kW)
  12. 50-shaft-horsepower (37 kW)
  13. 50-shaft-horsepower (37 kW)
  14. 50-shaft-horsepower (37 kW)
  15. 50-shaft-horsepower (37 kW)
  16. 50-horsepower (37 kW)
  17. 50-horsepower (37 kW)