Python regular expressions match instances of IP addresses
- 2020-04-02 14:15:21
- OfStack
This article illustrates a regular expression matching IP address example. The code structure is very straightforward. Share with you for your reference.
The main implementation code is as follows:
import re
reip = re.compile(r'(?<![.d])(?:d{1,3}.){3}d{1,3}(?![.d])')
for ip in reip.findall(line):
print "ip>>>", ip
PS: on the regular, here for you to recommend two very convenient regular expression tools for your reference:
JavaScript regular expression online testing tool:
(link: http://tools.jb51.net/regex/javascript)
Regular expression online generation tool:
(link: http://tools.jb51.net/regex/create_reg)
I hope this article has helped you with your Python programming.