Community
    • Login

    REGEX GROUP cuts off data

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    ip addressregexregex
    2 Posts 2 Posters 2.1k Views 2 Watching
    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 Offline
      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 Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors