0

Im try to match ip addresses and have come up with the following regular expression for python. I just cannot understand why this wont work. Any help would be greatly appreciated!

r"[0-255]\.[0-255]\.[0-255]\.[0-255]"
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
Darragh O'Flaherty
  • 995
  • 3
  • 13
  • 30

1 Answers1

2

Because [0-255] means any char between 0 to 2 or 5. switch to something like

r"^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142