none
Regex to identify IPv4 strings

    Question

  • Hi,

    I am trying to find regex that could identify IPv4 pattern correctly.
    Well my requirement is that it should identify following source patterns:

    192.168.0.4
    192.168.0.99/8080

    And will not identify the following patterns:
    1.1.1.99.3.192.168.0.4
    (too many groups of digits)

    192.168.0.99/808090
    (too many digits in the port number)

    12.192.168.0.99/8080
    (too many groups of digits in the address)


    Could someone please help me with a regex that identifies the same?
    This is quite a urgent requirement for me and i am stuck.

    Thanks,
    Saheli


    saheli

    • Moved by litdev Sunday, July 19, 2015 9:40 AM
    Monday, July 13, 2015 8:08 PM

Answers

  • Hello,

    A simple Bing search would have provided the information you require.

    What language are you using?

    If it's a .Net language, you can search ".Net IPV4 Regex"

    If it's Visual Basic for Applications, you could search "VBA IPv4 regex"

    For PowerShell (technically, a .Net scripting environment),  "PowerShell IPv4 regex"

    Or, generically, "IPV4 Regex"

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})


    Monday, July 20, 2015 2:55 PM
    Moderator

All replies

  • Hello Saheli,

    Here is Small Basic forum that is for Microsoft Small Basic programming language.  Your question seems to be off topic here.

    I think you can find "IPv4 regular expression" like 192.168.0.4 by searching website with your browser. 


    Nonki Takahashi

    Tuesday, July 14, 2015 7:15 AM
  • Hello,

    A simple Bing search would have provided the information you require.

    What language are you using?

    If it's a .Net language, you can search ".Net IPV4 Regex"

    If it's Visual Basic for Applications, you could search "VBA IPv4 regex"

    For PowerShell (technically, a .Net scripting environment),  "PowerShell IPv4 regex"

    Or, generically, "IPV4 Regex"

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer.
    My Blog: Unlock PowerShell
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join('6D73646E5F6B61726C406F75746C6F6F6B2E636F6D'-split'(?<=\G.{2})'|%{if($_){[char][int]"0x$_"}})


    Monday, July 20, 2015 2:55 PM
    Moderator