0

I'm using re.sub to match and replace everything that is not a number (positive or negative). So for instance: i want "-1" to stay "-1" but

  • "1" to stay "1"
  • -1$" to become "-1"
  • "a" to become ""

I have tried with:

re.sub('^(-?\d)', "", "-1") 
re.sub('^(-?\d)', "", "1")

But it behave the opposite way, not taking into account the ^ negation

OTmn
  • 185
  • 1
  • 2
  • 16

0 Answers0