Community
    • Login

    REGEX GROUP cuts off data

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    ip addressregexregex
    2 Posts 2 Posters 1.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • spicklesS
      spickles
      last edited by spickles

      I’m using the following regex to find an IP address in ‘slash’ notation.

      String = D EX 192.168.254.0/24 [170/1252608] via 172.29.104.5, 3w0d, Vlan104
      Regex = (([0-2]?[0-9]?[0-9].){3}([0-2]?[0-9]?[0-9])/[1-3]?[1-9])

      When I find using the regex it matches. However, when I select ‘\1’ for replace (without quotes) to keep just the group match, the IP address has digits removed. For example, if the IP address were a 10.x network the result returns 0.x and cuts off the ‘1’. If the address is 172.16.x it cuts off the ‘172’. If I change the regex to explicitly expect 10.x, 172.x, 192.x, etc. it works fine.

      Regex = ^.(10.([0-2]?[0-9]?[0-9].){2}([0-2]?[0-9]?[0-9])/[1-3]?[1-9]).$
      Regex = ^.(172.([0-2]?[0-9]?[0-9].){2}([0-2]?[0-9]?[0-9])/[1-3]?[1-9]).$
      Regex = ^.(192.([0-2]?[0-9]?[0-9].){2}([0-2]?[0-9]?[0-9])/[1-3]?[1-9]).$

      Claudia FrankC 1 Reply Last reply Reply Quote 0
      • Claudia FrankC
        Claudia Frank @spickles
        last edited by

        Hello @spickles
        one thing might be that you did not escape the forward slash !?
        But the replace … you want to replace the part which is found with the part which is found … ???

        Cheers
        Claudia

        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors