How to detect dot (.), underscore(_) and dash(-) in regex [on hold]












0














I need to process information dealing with IP address or folders containing information about an IP host.



I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file . For example



127.0.0.10
127-0-0-10
127_0_0_10


should all match. above. Is there any tokenizer regex to do this in bash?










share|improve this question







New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Michael Homer, RalfFriedl, Jeff Schaller, roaima, JigglyNaga 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 4




    Matching IP addresses with regex is no easy task. How accurate should your match be? Should it fail for an address of 0.0.0.0 or 10.10.10.256?
    – Jesse_b
    yesterday






  • 4




    how are you matching? with wildcards? with grep? with a bash [[ =~ ]] test?
    – Jeff Schaller
    yesterday










  • IPv4 or IPv6? Or both?
    – roaima
    yesterday










  • "I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file". Pretty much the only thing that will match all these requirements is a full wildcard .*, at which point you might as well abandon any idea of matching with REs. Or did you mean to match just the IP address component within those different types of string? Please be precise when describing what you need. Ideally provide examples of the different matches required.
    – roaima
    yesterday








  • 1




    127-0-0-10 isn't standard notation for an IPv4 address. Is this some sort of exception to the pattern matching requirement?
    – roaima
    yesterday
















0














I need to process information dealing with IP address or folders containing information about an IP host.



I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file . For example



127.0.0.10
127-0-0-10
127_0_0_10


should all match. above. Is there any tokenizer regex to do this in bash?










share|improve this question







New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











put on hold as unclear what you're asking by Michael Homer, RalfFriedl, Jeff Schaller, roaima, JigglyNaga 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 4




    Matching IP addresses with regex is no easy task. How accurate should your match be? Should it fail for an address of 0.0.0.0 or 10.10.10.256?
    – Jesse_b
    yesterday






  • 4




    how are you matching? with wildcards? with grep? with a bash [[ =~ ]] test?
    – Jeff Schaller
    yesterday










  • IPv4 or IPv6? Or both?
    – roaima
    yesterday










  • "I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file". Pretty much the only thing that will match all these requirements is a full wildcard .*, at which point you might as well abandon any idea of matching with REs. Or did you mean to match just the IP address component within those different types of string? Please be precise when describing what you need. Ideally provide examples of the different matches required.
    – roaima
    yesterday








  • 1




    127-0-0-10 isn't standard notation for an IPv4 address. Is this some sort of exception to the pattern matching requirement?
    – roaima
    yesterday














0












0








0







I need to process information dealing with IP address or folders containing information about an IP host.



I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file . For example



127.0.0.10
127-0-0-10
127_0_0_10


should all match. above. Is there any tokenizer regex to do this in bash?










share|improve this question







New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I need to process information dealing with IP address or folders containing information about an IP host.



I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file . For example



127.0.0.10
127-0-0-10
127_0_0_10


should all match. above. Is there any tokenizer regex to do this in bash?







bash regular-expression ip-address






share|improve this question







New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked yesterday









Nederealm

104




104




New contributor




Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Nederealm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as unclear what you're asking by Michael Homer, RalfFriedl, Jeff Schaller, roaima, JigglyNaga 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






put on hold as unclear what you're asking by Michael Homer, RalfFriedl, Jeff Schaller, roaima, JigglyNaga 14 hours ago


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 4




    Matching IP addresses with regex is no easy task. How accurate should your match be? Should it fail for an address of 0.0.0.0 or 10.10.10.256?
    – Jesse_b
    yesterday






  • 4




    how are you matching? with wildcards? with grep? with a bash [[ =~ ]] test?
    – Jeff Schaller
    yesterday










  • IPv4 or IPv6? Or both?
    – roaima
    yesterday










  • "I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file". Pretty much the only thing that will match all these requirements is a full wildcard .*, at which point you might as well abandon any idea of matching with REs. Or did you mean to match just the IP address component within those different types of string? Please be precise when describing what you need. Ideally provide examples of the different matches required.
    – roaima
    yesterday








  • 1




    127-0-0-10 isn't standard notation for an IPv4 address. Is this some sort of exception to the pattern matching requirement?
    – roaima
    yesterday














  • 4




    Matching IP addresses with regex is no easy task. How accurate should your match be? Should it fail for an address of 0.0.0.0 or 10.10.10.256?
    – Jesse_b
    yesterday






  • 4




    how are you matching? with wildcards? with grep? with a bash [[ =~ ]] test?
    – Jeff Schaller
    yesterday










  • IPv4 or IPv6? Or both?
    – roaima
    yesterday










  • "I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file". Pretty much the only thing that will match all these requirements is a full wildcard .*, at which point you might as well abandon any idea of matching with REs. Or did you mean to match just the IP address component within those different types of string? Please be precise when describing what you need. Ideally provide examples of the different matches required.
    – roaima
    yesterday








  • 1




    127-0-0-10 isn't standard notation for an IPv4 address. Is this some sort of exception to the pattern matching requirement?
    – roaima
    yesterday








4




4




Matching IP addresses with regex is no easy task. How accurate should your match be? Should it fail for an address of 0.0.0.0 or 10.10.10.256?
– Jesse_b
yesterday




Matching IP addresses with regex is no easy task. How accurate should your match be? Should it fail for an address of 0.0.0.0 or 10.10.10.256?
– Jesse_b
yesterday




4




4




how are you matching? with wildcards? with grep? with a bash [[ =~ ]] test?
– Jeff Schaller
yesterday




how are you matching? with wildcards? with grep? with a bash [[ =~ ]] test?
– Jeff Schaller
yesterday












IPv4 or IPv6? Or both?
– roaima
yesterday




IPv4 or IPv6? Or both?
– roaima
yesterday












"I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file". Pretty much the only thing that will match all these requirements is a full wildcard .*, at which point you might as well abandon any idea of matching with REs. Or did you mean to match just the IP address component within those different types of string? Please be precise when describing what you need. Ideally provide examples of the different matches required.
– roaima
yesterday






"I need a pattern that can identify (match) IP addresses, whether an actual url, name of folder or data file". Pretty much the only thing that will match all these requirements is a full wildcard .*, at which point you might as well abandon any idea of matching with REs. Or did you mean to match just the IP address component within those different types of string? Please be precise when describing what you need. Ideally provide examples of the different matches required.
– roaima
yesterday






1




1




127-0-0-10 isn't standard notation for an IPv4 address. Is this some sort of exception to the pattern matching requirement?
– roaima
yesterday




127-0-0-10 isn't standard notation for an IPv4 address. Is this some sort of exception to the pattern matching requirement?
– roaima
yesterday










1 Answer
1






active

oldest

votes


















2














The following regex seems to accomplish what you need:



b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b




$ cat test.txt
127.0.0.10
127-0-0-10
127_0_0_10
256_5_10_1
10-10-100-1
192.168.100.1
$ grep -E 'b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b' test.txt
127.0.0.10
127-0-0-10
127_0_0_10
10-10-100-1
192.168.100.1




See https://www.regular-expressions.info/ip.html for an explanation of the regex. I have simply modified the .s with [-._] so that it will match -, ., or _.






share|improve this answer




























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    The following regex seems to accomplish what you need:



    b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b




    $ cat test.txt
    127.0.0.10
    127-0-0-10
    127_0_0_10
    256_5_10_1
    10-10-100-1
    192.168.100.1
    $ grep -E 'b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b' test.txt
    127.0.0.10
    127-0-0-10
    127_0_0_10
    10-10-100-1
    192.168.100.1




    See https://www.regular-expressions.info/ip.html for an explanation of the regex. I have simply modified the .s with [-._] so that it will match -, ., or _.






    share|improve this answer


























      2














      The following regex seems to accomplish what you need:



      b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b




      $ cat test.txt
      127.0.0.10
      127-0-0-10
      127_0_0_10
      256_5_10_1
      10-10-100-1
      192.168.100.1
      $ grep -E 'b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b' test.txt
      127.0.0.10
      127-0-0-10
      127_0_0_10
      10-10-100-1
      192.168.100.1




      See https://www.regular-expressions.info/ip.html for an explanation of the regex. I have simply modified the .s with [-._] so that it will match -, ., or _.






      share|improve this answer
























        2












        2








        2






        The following regex seems to accomplish what you need:



        b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b




        $ cat test.txt
        127.0.0.10
        127-0-0-10
        127_0_0_10
        256_5_10_1
        10-10-100-1
        192.168.100.1
        $ grep -E 'b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b' test.txt
        127.0.0.10
        127-0-0-10
        127_0_0_10
        10-10-100-1
        192.168.100.1




        See https://www.regular-expressions.info/ip.html for an explanation of the regex. I have simply modified the .s with [-._] so that it will match -, ., or _.






        share|improve this answer












        The following regex seems to accomplish what you need:



        b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b




        $ cat test.txt
        127.0.0.10
        127-0-0-10
        127_0_0_10
        256_5_10_1
        10-10-100-1
        192.168.100.1
        $ grep -E 'b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])[-._](25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])b' test.txt
        127.0.0.10
        127-0-0-10
        127_0_0_10
        10-10-100-1
        192.168.100.1




        See https://www.regular-expressions.info/ip.html for an explanation of the regex. I have simply modified the .s with [-._] so that it will match -, ., or _.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Jesse_b

        11.7k23064




        11.7k23064















            Popular posts from this blog

            Entries order in /etc/network/interfaces

            新発田市

            Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)