Regular Expressions 101

Community Patterns

Community Library Entry

0

Regular Expression
Python

r"
(?:\d+\s*[\s+|\-+]\s*\d+\s*\/\s*\d+(?!\d*\s*\-))
"
gm

Description

Convert fractions in for of 7 1/2 or 7-1/2 with optional spacing to 7.5 avoiding expressions like 5-7 / 10-11 to be mistaken as 5-7/10

Submitted by Waleed Kilany - 2 years ago