Community
    • Login

    delete text before | and then, using notepad

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 3 Posters 1.7k 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.
    • peterfrankw3P
      peterfrankw3
      last edited by

      I am trying to use notepad++ and regular expressions to edit a document. I have text in this format

      10.10.1.0|mery@me.com|phone23456|name1|http:201.150.1.0|git
      10.255.255.57|damy@yahoo.us|http:223.150.1.9|firstgoo
      201.150.1.0|candol_tr@hotmail.com|phone4567|home345|http:278.189.1.9

      How would I do that to get this:

      mery@me.com|name1
      damy@yahoo.us|firstgoo
      candol_tr@hotmail.com|home345

      thanks you

      1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R
        last edited by Terry R

        @peterfrankw3
        your problem intrigued me so I felt I had to solve it. From your example I assumed that the | is a delimiter and that you can have anywhere from 4 fields upwards (example shows 4, 5 and 6 fields). I also assumed that you want the 2nd and 4th field every time with the delimiter between.

        So my regex (regular expression) requires that the search mode under “Replace” function is set to “regular expression” and also have the wrap around ticked.
        Find What:(?-s)^[^\|]+[\|]([^|]+)([\|])[^|]+[\|]([^|\r\n]+).+(\R|\z)
        Replace With:\1\2\3\4
        You should be able to copy the Find What field directly (grab the red text) and it’s probably best to do so.
        It might look a bit daunting but what we have is:
        ^[^|]+ :start at beginning of line and consume characters so long as a | is not encountered.
        [|] :consume 1 character which should be the | as the previous expression had to stop when the next character was a |.
        The next 4 expressions repeat the prior ones. The round brackets around some allows up to keep the characters we capture in those portions of the expression.
        ([^|\r\n]+) consumes characters until either a | or an end of line is encountered. This is needed as we don’t know whether the line is ONLY 4 fields or more.
        (\R|\z) consumes an end of line or end of file.
        We capture the groups we need and then recreate them (including the end of line/file) to replace the line.

        See how it works on your data and come back if further issues which might require modification of the regex, or even to let us know if it worked.

        Terry

        1 Reply Last reply Reply Quote 3
        • Terry RT
          Terry R
          last edited by

          @peterfrankw3
          You may have noticed some \ missing from my description, I did not until now. It is an unfortunate side effect of the window you type the post in. Its interpreted and sometimes this (or worse) happens. I hope you got the idea anyways.

          Terry

          1 Reply Last reply Reply Quote 0
          • peterfrankw3P
            peterfrankw3
            last edited by

            thank you very much friend for helping me, very good clarification

            1 Reply Last reply Reply Quote 0
            • guy038G
              guy038
              last edited by guy038

              Hello, @peterfrankw3, @terry-r and All,

              Just a variant of your regex, which uses lazy quantifiers and non capturing groups :

              SEARCH (?-s).+?\|(.+?)\|.+?(\|.+?)(?:\|.+)?(?:\R|\z)

              REPLACE \1\2\r\n

              Cheers,

              guy038

              peterfrankw3P 1 Reply Last reply Reply Quote 4
              • peterfrankw3P
                peterfrankw3 @guy038
                last edited by

                @guy038 , thanks you

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