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
  • 28,235
  • 15
  • 95
  • 135
Darragh O'Flaherty
  • 945
  • 3
  • 11
  • 28

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
  • 28,235
  • 15
  • 95
  • 135