how Find the specific IP in the IP list in notpad++



  • hi guys
    i want find the specific IP in the IP list for example my list ip

    95.110.175.247
    156.54.22.245
    156.54.169.185
    185.63.52.110
    156.54.172.100
    185.148.108.97
    95.110.129.163
    88.42.240.186
    95.141.40.109
    79.1.194.161
    188.15.252.240
    80.211.38.119
    185.152.253.206
    151.73.164.65
    156.54.180.88
    128.116.133.119

    i want find example ip begain with 185.150.. (* mean 0-255)

    resualt my list

    185.152.253.206

    find resualt 185.(number larg of 150 to 255 ).(any number 0-255).(any number 0-255)
    thanks for help me and sorry my bad english



  • Hi @The-Best-Of-Voice

    Try the following regex:

    Search: ^185\.(1[5-9][0-9]|2[0-4]\d|25[0-5])(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){2}$
    

    Have fun!



  • Hello, @the-best-of-voice, @astrosofista and All,

    Your regex does the job nicely !

    I take this opportunity to point out another method. The idea is to define the regex which finds any individual byte of an IPV4 address, in a group, so the regex (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d) and use it to search the overall address with the regex \b(?#)(\.(?#)){3}\b where (?#) is a subroutine call to group #

    So the regex to search any valid IPV4 address is :

    (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(*F)|\b(?1)(\.(?1)){3}\b

    This regex is composed of two alternatives :

    • (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(*F) which defines an individual byte of an IPV4 address as group 1 The important fact is that this definition is followed with the (*F) backtracking control verb ( or (*FAIL) )

    • \b(?1)(\.(?1)){3}\b which searches for the complete IPV4 address

    So the regex engine first stores the definition of the individual byte in group 1 and, as it meets the (*F) syntax, the current match is considered unsuccessful. Then the regex engine tries out if other match attempts are possible and it tests the second alternative. Note that the subroutine call (?1) is STILL  defined, although the first alternative was cancelled because of the (*F) backtracking control verb

    Refer here for additional information about these special verbs

    In a nutshell :

    • (?1) represents an individual byte of an IPV4 address 25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d

    • The second alternative is just equivalent to the regex (?1)\.(?1)\.(?1)\.(?1) between two \b boundaries and does find any valid IPV4 address


    Now, to solve the OP problem and using the same idea as above, we’ll use the following regex S/R :

    SEARCH (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(*F)|\b185\.(25[0-5]|2[0-4]\d|1[5-9]\d)\.(?1)\.(?1)\b

    Best Regards,

    guy038



  • Hi @guy038

    Very nice, thank you. I have saved it and hope to apply it soon.

    Have fun!



  • @guy038 said in how Find the specific IP in the IP list in notpad++:

    (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(*F) which defines an individual byte of an IPV4 address as group 1 The important fact is that this definition is followed with the (*F) backtracking control verb ( or (*FAIL) )

    Interesting use of (*FAIL), Guy.

    After looking at that in detail, it rather surprises me that you used “fail”, rather than "define"ing:

    (?(DEFINE)(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))\b(?1)(\.(?1)){3}\b

    Maybe you were having a “fail” kind of day rather than a “define” kind of day!
    If so, I’m sorry to hear that! :-)

    Or maybe you were just presenting a different spin on the IP address parsing technique – perhaps you’ve shown that one before using “define” (I can’t recall).



  • Hi @alan-kilborn,

    No, be reassured, this fortunately has nothing to do with my mood ;-)))

    And, in the Remark section of this post, I do speak about the (DEFINE) method and about my personal method, too !

    Indeed, there are three means to achieve the same thing :

    • (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(*F)|Regex to match

    • (?(DEFINE)(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d))Regex to match

    • (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)Unknown char / string|Regex to match


    The last syntax, that I discovered, should help you to understand how the (*F) backtracking control verb acts !

    In this last syntax the Unknown char / string is any character or string which is not present in current file scanned. Thus, necessarily, the first alternative (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)Unknown char / string will never match !

    But, and this is the key point, the regex engine always tries this alternative, first and always defines the group 1, for further use, in the second alternative, assuming that you’re using a subroutine call to group 1, in the second alternative ;-))

    Best Regards,

    guy038



  • @guy038 said in how Find the specific IP in the IP list in notpad++:

    the last syntax, that I discovered, should help you to understand how the (*F) backtracking control verb acts !

    Well, I think I understand the usage, but I also think the “define” version, which also works, makes more intuitive sense. But I could be missing the point, I suppose. :-)



  • Hi, @alan-kilborn and All,

    I’m totally agree with you. The legal syntax is, indeed, the special conditional syntax ((?(DEFINE)...........). Just think about the word DEFINE, in upper case !

    Then, an alternative syntax could be, of course, (............)(*F). Indeed, in manuals, the DEFINE part is described as a part of regex which does never match anything, by principle !

    Finally, my syntax ( the third one ), although correct, should be considered as a user’s work-around !

    Cheers,

    guy038


Log in to reply