I am working on what is basically an IP detector regex.
Basically, I want to remove all numbers that do not have periods in them.
For instance, here are some sample inputs:
1 >Matches
12 >Matches
134 >Matches
156 >Matches
1567 >Matches
1.99 >No Match
.100 >Don't care
1.2.3.4 >No Match
.1.2.3.4 >No Match
This is used to remove all the matches. Matches are separated by space. For instance, if I inputted the string:
"14. 24. asf.d 7 .12 .498 .s g 14091 87.49 .sdf.gs.df 12874 ds.fgs 9.127.41 sd.fg 92.47 sd.fg 892.14 sd.fg .79 12 s.df 47 8 .sdfg 1.9 sdfg 2.4 71. s9 24 .ds.f.g 71.9 8 s.df 4 .g 7 132. .sdfg 4 s.dfg"
I might be returned something similar to the string:
"asf.d .s g 87.49 .sdf.gs.df ds.fgs 9.127.41 sd.fg 92.47 sd.fg 892.14 sd.fg s.df .sdfg 1.9 sdfg 2.4 s .ds.f.g 71.9 s.df .g .sdfg s.dfg"
I have gotten as far as:
([0-9]+)(?=)
But I am not sure how to make the regex ignore the numbers if they have periods in them ( and actually, I am not sure how to get it to first select numbers even if they have periods in them!)
You could try this regular expression:
Explanation:
(?<![0-9.]): Negative look behind. Previous character is not 0-9 or a dot.[0-9]+: One or more digits in 0-9.(?![0-9.]): Negative look ahead. Next character is not 0-9 or a dot.