lexikos wrote:Masonjar13's variant fails with the input "11.1.1.1 -- 1.1.1.1". This was the reason for the extra "`n"s in my script...
Ah, I was wondering why; I hadn't considered that. And while I know that's not the only form of IP address, nor the only version of, I was just keeping it to his question.
lexikos wrote:I think you will probably find countless regexes and discussions of validating IP addresses if you search outside of this forum.
Sure did. It's quite the topic, apparently.
lexikos wrote:I suppose that \b([12]?\d\d?)(?:\.(?1)){3}\b is adequate.
Using that, I made a new test script, using
this IP database. It correctly retrieves all of them without duplicates.
Code: Select all
pos:=1,str:="`n",cnt:=0
fileRead,test,us.csv
oTest:="bla 8.8.8.8 bla 12.34.43.21 bla 1.234.43.21 bla 1.234.43.210 bla 8.8.8.8 bla 11.1.1.1 -- 1.1.1.1`n"
test.=oTest test
while(pos:=regExMatch(test,"\b([12]?\d\d?)(?:\.(?1)){3}\b",match,pos + strLen(match)))
if(!inStr(str,"`n" match "`n"))
str.=match "`n",cnt++
gui,add,edit,r30 w700,% lTrim(str,"`n") "`nIteration count: " cnt
gui,show
return
guiClose:
exitApp
The list could use more variety for better testing, but it was the first one I found.