You can use re.sub(pattern, repl, string)for this.
Let me use this regex to match:
([a-z])[A-Z].*?( )
([a-z]), [A-Z] .*?, ( ).
, \1 \2 re.sub:
new_text = re.sub(r"([a-z])[A-Z].*?( )", r"\1\2", text)
:
team pts/g
St. Louis Rams 32.875
Washington Redskins 27.6875
Minnesota Vikings 24.9375
Indianapolis Colts 26.4375
Oakland Raiders 24.375
Carolina Panthers 26.3125
Jacksonville Jaguars 24.75
Chicago Bears 17.0
Green Bay Packers 22.3125
San Francisco 49ers 18.4375
Buffalo Bills 20.0
. , , , re.sub, Match a str:
def replace_with_spaces(match):
return match.group(1) + " "*len(match.group(2)) + match.group(3)
( , , , ):
new_text re.sub(r"([a-z])([A-Z].*?)( )", replace_with_spaces, text)
:
team pts/g
St. Louis Rams 32.875
Washington Redskins 27.687
Minnesota Vikings 24.937
Indianapolis Colts 26.437
Oakland Raiders 24.375
Carolina Panthers 26.312
Jacksonville Jaguars 24.75
Chicago Bears 17.0
Green Bay Packers 22.312
San Francisco 49ers 18.437
Buffalo Bills 20.0