• Login
Community
  • Login

remove string after a limiter

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
6 Posts 4 Posters 507 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.
  • C
    Clyde Parker
    last edited by Feb 5, 2021, 9:24 PM

    Hello everyone, so i wanted to clear a list which has a limiter " || " already tried experimenting with some regex
    here’s an example of the content in the files
    client@mail.com :orderID || Payment Date
    So what i’m trying to do is remove " || Payment Date " with regex, i can’t just replace the string because everyline would have a different date. all i can do is use the " || " as reference because it constant
    thank you!

    A A 2 Replies Last reply Feb 5, 2021, 9:35 PM Reply Quote 0
    • A
      Alan Kilborn @Clyde Parker
      last edited by Feb 5, 2021, 9:35 PM

      @Clyde-Parker

      find: (?-s)\|\|.+
      repl: nothing

      1 Reply Last reply Reply Quote 4
      • C
        Clyde Parker
        last edited by Feb 5, 2021, 9:36 PM

        Works like charm, tysm

        1 Reply Last reply Reply Quote 0
        • A
          astrosofista @Clyde Parker
          last edited by astrosofista Feb 5, 2021, 9:37 PM Feb 5, 2021, 9:37 PM

          Hi @Clyde-Parker

          Please try this regex,

          Search: (?-s)^.+?\K\Q ||\E.+$
          Replace: [leave empty]
          

          Put the caret at the very beginning of the file, select just the Regular Expressions mode and click on Replace All.

          Take care and have fun!

          Edit: Alan beat me!

          1 Reply Last reply Reply Quote 4
          • G
            guy038
            last edited by guy038 Feb 5, 2021, 11:15 PM Feb 5, 2021, 10:04 PM

            Hi, @clyde-parker, @alan-kilborn, @astrosofista and All,

            Alan beat me too. Moreover, with exactly the same regex :-)


            @clyde-parker, this search regex is quite obvious !

            Notes :

            • First the (?-s) is an in-line modifier which forces the regex engine to see any meta-character . as matching a single standard char ( so not the EOL characters )

            • Then the part \|\| represents two literal pipe characters. They must be escaped as | is the meta-character for defining alternatives

            • Finally, the part .+ matches for any non-empty range of standard characters …till the end of current line, so any existing Payment Date

            • The overall match ||Payment Date, is simply deleted as the replacement zone is empty


            To learn how to build regular expressions, I strongly advice you to carefully read this FAQ. It should not be difficult to master the basic concepts, in a week or so ;-))

            Best Regards,

            guy038

            A 1 Reply Last reply Feb 5, 2021, 10:07 PM Reply Quote 3
            • A
              Alan Kilborn @guy038
              last edited by Feb 5, 2021, 10:07 PM

              @guy038 said in remove string after a limiter:

              Alan beat me too. Moreover, with exactly the same regex :-)

              Haha, well does this show that some of us are learning?
              See, it can happen, people!

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