I need a regex that matches ips like 192.1.2.33/23 but even in case of spaces or newlines, for example:
30.0.
0.0/24
I tried this one:
\b(((\s+)?[1-9](\s+)?[0-9]?(\s+)?[0-9]?(\s+)?)\.((\s+)?[0-9](\s+)?[0-9]?(\s+)?[0-9]?(\s+)?)\.((\s+)?[0-9](\s+)?[0-9]?(\s+)?[0-9]?(\s+)?)\.((\s+)?[0-9](\s+)?[0-9]?(\s+)?[0-9]?(\s+)?)\/((\s+)?[0-9](\s+)?[0-9]?(\s+)?))\b
But doesn't work well... (also, its so damn long!)
Any help is appreciated.
EDIT:
When I try to use it with Python, sometimes it just strips off numbers when there are cases of newlines. Here is the code I use:
with open(r"AllText.txt") as fp:
for line in fp:
for i in re.finditer(regexp_v3, line):
print i.group()
For example try it on this text:
"172.18.177.240/28","ewwefwfwef","172.18.176.240/28","D.edwefwefwef
e_fe","172.18.230.0/24","172.18.177.128/28","dewefgw-1.wefre_fe","172.18.176.128/28","efSwefefef.eI-nc_rwefstowefe","17
2.18.183.0/24","PAT
EDIT 2:
The problem is "You are reading the file row by row and match your regex always only against a single row. How should the regex start matching from end of row a when it sees only row b?"
So, the question now is: how can I read all "at once" to allow the regex to see everything?