Community
    • Login

    subnets, search/find and regular expression, txt2xml

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 555 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.
    • V Offline
      vasstr
      last edited by

      Hello,

      I would like to replace line by line.

      e.g. txt file

      3.5.140.0/255.255.252.0
      15.190.244.0/255.255.252.0
      15.230.15.76/255.255.255.254
      

      with the following:

      xml file:

        <IPHost transactionid="">
          <Name>n3.5.140.0</Name>
          <Description>subnet</Description>
          <IPFamily>IPv4</IPFamily>
          <HostType>Network</HostType>
          <IPAddress>3.5.140.0</IPAddress>
          <Subnet>255.255.252.0</Subnet>
        </IPHost>
        <IPHost transactionid="">
          <Name>n15.190.244.0</Name>
          <Description>subnet</Description>
          <IPFamily>IPv4</IPFamily>
          <HostType>Network</HostType>
          <IPAddress>15.190.244.0</IPAddress>
          <Subnet>255.255.252.0</Subnet>
        </IPHost>
        <IPHost transactionid="">
          <Name>n15.230.15.76</Name>
          <Description>ap-northeast-2</Description>
          <IPFamily>IPv4</IPFamily>
          <HostType>Network</HostType>
          <IPAddress>3.5.140.0</IPAddress>
          <Subnet>255.255.252.0</Subnet>
        </IPHost>
        <IPHost transactionid="">
          <Name>15.230.15.76</Name>
          <Description>subnet</Description>
          <IPFamily>IPv4</IPFamily>
          <HostType>Network</HostType>
          <IPAddress>15.230.15.76</IPAddress>
          <Subnet>255.255.255.254</Subnet>
        </IPHost>
      

      How is this possible ? search/find and regular expression?

      Best regards, Tryf

      -–

      moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP Online
        PeterJones @vasstr
        last edited by

        @vasstr said in subnets, search/find and regular expression, txt2xml:

        search/find and regular expression?

        Yep.

        FIND WHAT = ^(\d+\.\d+\.\d+\.\d+)/(\d+\.\d+\.\d+\.\d+)
        REPLACE WITH = <IPHost transactionid="">\r\n <Name>n$1</Name>\r\n <Description>subnet</Description>\r\n <IPFamily>IPv4</IPFamily>\r\n <HostType>Network</HostType>\r\n <IPAddress>$1</IPAddress>\r\n <Subnet>$2</Subnet>\r\n</IPHost>
        SEARCH MODE = Regular Expression
        REPLACE ALL

        Notes:

        • ^ makes sure the match must start at the beginning of a line
        • each \d+\.\d+\.\d+\.\d+ match four dot-separated integers
        • The parens around those put them in two groups
        • The $1 and $2 in the replacement refer to the values of group1 and group2, respectively
        • the \r\n in the replacement are the standard windows CRLF end-of-line sequence, so that your replacement can go over multiple lines.

        -—

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 1

        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