Community
    • Login

    How to delete "(....)" but only in certain lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    13 Posts 4 Posters 1.5k 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.
    • PeterJonesP
      PeterJones @Imgema
      last edited by PeterJones

      @imgema ,

      This post gives a formula for how to do a search-and-replace, but make it match only when it’s between certain start and end triggers (the BSR and ESR of that post’s formula).

      The only difficult thing about applying that formula to your use-case is that you want to match literal parentheses, which have special meaning in regular expressions. For that, I believe the regular expression you will want for FR will be \h?\(.*?\) . (The \h? says that it will match the space before the open-( if there is one; the \ before the ( and ) is the regex indicator that the character following should be treated as a literal character instead of its regex special meaning)

      ----

      Useful References

      • Please Read Before Posting
      • Template for Search/Replace Questions
      • FAQ: Where to find regular expressions (regex) documentation
      • Notepad++ Online User Manual: Searching/Regex
      ImgemaI 1 Reply Last reply Reply Quote 1
      • ImgemaI
        Imgema @PeterJones
        last edited by

        @peterjones

        Thanks but this code also replaces the (…) from the descriptions

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

          @imgema ,

          Not if you followed the directions in the post I linked you to. FR doesn’t go by itself in the Find box; there are other pieces that are required for the logic to work.

          But that other post explains exactly what you need to do: You have to figure out what the BSR, ESR, and RR need to be for your circumstances – it’s pretty easy to do, since those are just the “begin” and “end” conditions for which sections you want to include (I’ll give you a hint: those values will look a lot like XML tags), and since you want to replace it with nothing, I think RR will be obvious. Once you have figured out what those values need to be, you have to look at the expression that Guy supplied in that post I linked you to, and type those values instead of FR, BSR, ESR, and RR in the Find/Replace boxes.

          ImgemaI 1 Reply Last reply Reply Quote 1
          • ImgemaI
            Imgema @PeterJones
            last edited by

            @peterjones
            I’m sorry, this is over my head. I don’t know what these FR and BSR words mean.

            I was looking for a code to use as is.

            Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 0
            • Alan KilbornA
              Alan Kilborn @Imgema
              last edited by

              @imgema said in How to delete "(....)" but only in certain lines:

              I’m sorry, this is over my head.

              It can’t be, this is your data you need to manipulate.

              I don’t know what these FR and BSR words mean.

              Did you even read the linked posting?
              It’s all right there.

              I was looking for a code to use as is.

              Sure, I wish I had someone to do all my work for me, too.

              ImgemaI 1 Reply Last reply Reply Quote 2
              • ImgemaI
                Imgema @Alan Kilborn
                last edited by

                Not really my data, i don’t know how to code, i’m trying to modify a xml that was generated by a program.

                Thanks anyway, i’ll try to maybe figure it out then.

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

                  @imgema ,

                  Remember the old adage, “Give a man a fish, feed him for a day; teach a man to fish, feed him for a lifetime”? I was trying to teach, rather than than give. Sorry.

                  Here are the steps I was hoping you would be able to figure out.

                  Step 1: Read the post I linked you to.
                  Step 2: find the formula I mentioned

                  • Let FR (Find Regex ) be the regex which defines the char, string or expression to be searched
                  • Let RR (Replacement Regex ) be the regex which defines the char, string or expression which must replace the FR expression
                  • Let BSR ( Begin Search-region Regex ) be the regex which defines the beginning of the area where the search for FR, must start
                  • Let ESR ( End Search-region Regex) be the regex which defines, implicitly, the area where the search for FR, must end

                  Then, the generic regex can be expressed :
                  SEARCH (?-i:BSR|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:FR)
                  REPLACE RR

                  Step3: Figure out what FR should be: I gave you this already: \h?\(.*?\)
                  Step4: Figure out what BSR should be: I gave you hints already: <name>
                  Step5: Figure out what ESR should be: I gave you hints already: </name>
                  Step6: Figure out what RR should be: I think this is obviously the empty string
                  Step7: plug those back in:

                  • 7a: plug FR into the expression: (?-i:BSR|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:\h?\(.*?\))
                  • 7b: plug BSR into the expression: (?-i:<name>|(?!\A)\G)(?s:(?!ESR).)*?\K(?-i:\h?\(.*?\))
                  • 7c: plug ESR into the expression: (?-i:<name>|(?!\A)\G)(?s:(?!</name>).)*?\K(?-i:\h?\(.*?\))
                  • 7d: type that final expression from 7c into the FIND box

                  Step8: type the RR expression (the empty string) into the REPLACE box
                  Step9: check the Regular Expression box
                  Step10: click Replace All

                  It works:

                  BEFORE:
                  d14ae289-41b2-498f-9315-c1d69ef535c8-image.png

                  AFTER:
                  6eddab62-435d-44b1-b256-80aa686a155f-image.png

                  ImgemaI 1 Reply Last reply Reply Quote 2
                  • ImgemaI
                    Imgema @PeterJones
                    last edited by

                    @peterjones

                    Thanks for the guidelines and solution. I appreciate it.

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

                      Hi, @peterjones, @alan-kilborn, @terry-r, @astrosofista and All,

                      As I reported in the second part of this post :

                      https://community.notepad-plus-plus.org/post/74410

                      and with further explanations in this one :

                      https://community.notepad-plus-plus.org/post/74418

                      I suppose that we would take avantage to adopt the @hellena-crainicu syntax (?!^) ( instead of (?!\A) ) !

                      BR

                      guy038

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

                        @guy038 said in How to delete "(....)" but only in certain lines:

                        I suppose that we would take avantage to adopt the @hellena-crainicu syntax (?!^) ( instead of (?!\A) ) !

                        So how about adding that in the canonical posting linked above; this one to be specific:

                        https://community.notepad-plus-plus.org/post/62799

                        Please DON’T edit that posting, because a lot of things already like to that, and editing it now would make it confusing. Add a new post in that owner thread, with the updated technique. OR, maybe some brand new thread?

                        PeterJonesP 1 Reply Last reply Reply Quote 0
                        • PeterJonesP
                          PeterJones @Alan Kilborn
                          last edited by

                          @alan-kilborn said in How to delete "(....)" but only in certain lines:

                          OR, maybe some brand new thread?

                          I would second the brand-new-thread suggestion. That way, it doesn’t have the confusing context of a specific question with details that don’t match the person’s that we’re pointing to the post. (it goes back to my Developing generic regex sequences from last year, where I wanted to allow us to develop the generics in that thread, then when they were ready, spawn each generic off to a separate “official” topic, and maybe have a post in the FAQ that links to the “official” version)

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

                            Hello, @peterjones,

                            After further testing, I came to the conclusion to keep the present syntax (?\A). Refer to this post for some explanations :

                            https://community.notepad-plus-plus.org/post/74937

                            So, sorry for the noise. I’m going to reformat most of my notes, concerning this specific regex.

                            Then I will send it to you by mail for checking before finding a final destination for it !

                            Cheers,

                            guy038

                            1 Reply Last reply Reply Quote 0
                            • Neil SchipperN Neil Schipper referenced this topic on
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors