Community
    • Login

    Need help for regular expression - find, insert and delete

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 3 Posters 3.1k 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.
    • Alan KilbornA
      Alan Kilborn @Venus642
      last edited by

      @Venus642

      Perhaps this is a correct clarification:

      • If a | character is not found after the leading digits on a line, insert it with a space before it and a space after it

      • If a | character is found anywhere else in a line, remove it and anything that follows it (and any space before it)

      1 Reply Last reply Reply Quote 0
      • Venus642V
        Venus642
        last edited by

        Thanks Alan for your Info and help.

        How can I change that with regex?
        From:
        220 Txt Txt Txt
        To:
        220 | Txt Txt Txt

        Or delete and insert:
        From:
        10 Txt Txt Txt | 300
        To:
        10 | Txt Txt Txt

        Sorry. I have no idea how to make regex do it…

        Alan KilbornA astrosofistaA 2 Replies Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Venus642
          last edited by

          @Venus642

          I would do two separate steps:

          find: ^(\d+ )([^|])
          repl: ${1}| ${2}

          and then:

          find: (?-s)^(\d+ \|.*?) \|.*
          repl: ${1}

          Venus642V 1 Reply Last reply Reply Quote 3
          • Venus642V
            Venus642 @Alan Kilborn
            last edited by

            WooooooooW!
            Alan -Big big thanks for your help!

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • Alan KilbornA
              Alan Kilborn @Venus642
              last edited by

              @Venus642 said in Need help for regular expression - find, insert and delete:

              Big big thanks for your help!

              Pay back by learning about how it worked, so that next time you don’t have to ask. :-)

              Start with information HERE

              1 Reply Last reply Reply Quote 0
              • astrosofistaA
                astrosofista @Venus642
                last edited by

                Hi @Venus642, @Alan-Kilborn

                Another option, in one step:

                Search: (?-s)(?:^(\d+) *?([A-Za-z]+))|( *?\| *?\d+)$
                Replace: ?1($1 | $2)

                Have fun!

                Venus642V 1 Reply Last reply Reply Quote 1
                • Venus642V
                  Venus642 @astrosofista
                  last edited by

                  One step - Perfect…
                  Alan and astrosofist - Top help!

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA
                    Alan Kilborn @Venus642
                    last edited by

                    @Venus642 said in Need help for regular expression - find, insert and delete:

                    One step - Perfect…

                    Yea, I wouldn’t get too bogged down in it needing to be a one-step operation.
                    If it is something you need to do often, you will make it a macro anyway (so you can give it a meaningful name).
                    And if it is a macro, it can just as well be two replacement steps (because, by the nature of macros, multiple steps look like one step).

                    Venus642V 1 Reply Last reply Reply Quote 0
                    • Venus642V
                      Venus642 @Alan Kilborn
                      last edited by

                      @Alan-Kilborn
                      Alan I have tested again and your solutions is better in my case.

                      Alan KilbornA 1 Reply Last reply Reply Quote 1
                      • Alan KilbornA
                        Alan Kilborn @Venus642
                        last edited by

                        @Venus642 said in Need help for regular expression - find, insert and delete:

                        Alan … your solutions is better

                        Well, I certainly wasn’t trying to “win”. :-)
                        I often try to point out that a solution to such a problem doesn’t have to be all crammed into one operation.
                        It can make the operation harder to understand for a novice with regular expressions.

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