Community
    • Login

    How to replace a specific text in lines that contains a specific word.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    17 Posts 4 Posters 2.4k 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.
    • Zsombor SzarkaZ
      Zsombor Szarka @Alan Kilborn
      last edited by

      @alan-kilborn Thanks! It was a crazy fast reply!

      It did work almost perfectly. What i discovered, is that there are some lines, that contains “Ingot” (capital i) for some reason, and i would like to change them too. Can you modify your search so it will be independent from that factor? (of Course i can make two replaces with your syntax, i am just curious, what would be the solution for that)

      PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Zsombor Szarka
        last edited by PeterJones

        This post is deleted!
        1 Reply Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @Zsombor Szarka
          last edited by Alan Kilborn

          @zsombor-szarka said in How to replace a specific text in lines that contains a specific word.:

          some lines, that contains “Ingot” (capital i) for some reason, and i would like to change them too.

          Change the (?-is) part to (?i-s).

          OR

          Make that part (?-s) and then use the Match case checkbox to do your will.

          It did work almost perfectly.

          No it worked perfectly, not almost.
          Just because you left something out of your problem statement doesn’t mean the solution provided was deficient. :-)

          Zsombor SzarkaZ 1 Reply Last reply Reply Quote 2
          • guy038G
            guy038
            last edited by

            Hello @zsombor-szarka, @alan-kilborn, @peterjones and All,

            I may be wrong but I think that the correct search expression is rather :

            SEARCH (?i-s):ingot.*\Kfalse$

            Indeed, the part _false, before the = sign, must not be changed !

            Best Regards,

            guy038

            PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
            • PeterJonesP
              PeterJones @guy038
              last edited by

              @guy038 said in How to replace a specific text in lines that contains a specific word.:

              Indeed, the part _false, before the = sign, must not be changed !

              That’s why Alan’s expression has the .*?= before the \K, to make sure everything before and including the equals is consumed without change

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

                @guy038 said in How to replace a specific text in lines that contains a specific word.:

                I may be wrong but I think that the correct search expression

                I think the original is solution is fine.
                Perhaps the ?= in it is confusing (looks maybe like a (?=…) construct?)
                But really it just forces =false to be matched.

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

                  Hi, @zsombor-szarka, @alan-kilborn, @peterjones and All,

                  My bad ! Alan, I didn’t notice the equal sign in your version :-(

                  BR

                  guy038

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

                    @guy038

                    Not a problem, Guy.
                    Like I said maybe I shouldn’t have done it the way I did, because it really does look like that other construct.

                    BTW, good to see you posting.
                    You haven’t been very active lately.
                    Hopefully you are “back” and will be posting on a more regular basis now.

                    1 Reply Last reply Reply Quote 1
                    • Zsombor SzarkaZ
                      Zsombor Szarka @Alan Kilborn
                      last edited by

                      No it worked perfectly, not almost.
                      Just because you left something out of your problem statement doesn’t mean the solution provided was deficient. :-)

                      Well i can’t argue with that, i should have formulated my sentences better.
                      Anyway now it works as i wanted to, so thanks a lot!

                      Have a wonderful day!

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

                        @zsombor-szarka

                        I started to learn about the search mechanism of notepad++, but it’s way too complex for me to figure it out. (i spent an hour learning it so far)

                        Well, any time invested in this endeavor is time well spent (for the NEXT time).

                        Can you give … explain it too?

                        I basically gave the syntax: (?-s)ingot.*?=\Kfalse

                        It means:

                        (?-s) : don’t let a following . match a line-ending
                        ingot : match the literal text
                        .*? : match any characters zero or more times, minimally
                        = : match literal equal
                        \K : forget the match to this point (we don’t want to change ingot followed by whatever followed by =)
                        false : match the literal text

                        We replace with only true because the matched text will be false at this point.

                        Zsombor SzarkaZ 1 Reply Last reply Reply Quote 2
                        • Zsombor SzarkaZ
                          Zsombor Szarka @Alan Kilborn
                          last edited by Zsombor Szarka

                          @alan-kilborn
                          Thanks a lot (again)!
                          I understand everything except this line:

                          (?-s) : don’t let a following . match a line-ending

                          I can’t figure out what do you mean by that… Can you elaborate?

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

                            @zsombor-szarka said in How to replace a specific text in lines that contains a specific word.:

                            I understand everything except this

                            You even understand the \K fully? :-)

                            Ok so the (?-s) is equivalent to leaving this checkbox unchecked:

                            711e0e73-4177-4d94-a12b-2ac637b4aed8-image.png

                            But what it means is that using a . further along in the expression will NOT match a line-ending character.

                            When you originally said:

                            is to replace all the “=false” texts to “=true” in lines

                            The “in lines” part is a real key that (?-s) should be used.

                            Otherwise, you could get a match like this (definitely unwanted):

                            4011b833-cbb1-4cb8-837f-533cea84f352-image.png

                            Note that I changed your data a bit in the above.

                            See how there is a match on line 10 even though there is no ingot on line 10? The ingot part starts on line 9… :

                            e7e3961a-428a-41ac-a3fa-9d9b8feea192-image.png

                            Note that what I’m showing now is if you use (?s) instead of (?-s). The - turns off the ability to match line ending characters.

                            So the (?-s) is a safety-valve on the expression, in this instance saying “everything must be on the same line”.

                            Hopefully that makes a bit of sense.

                            Zsombor SzarkaZ 1 Reply Last reply Reply Quote 3
                            • Zsombor SzarkaZ
                              Zsombor Szarka @Alan Kilborn
                              last edited by

                              @alan-kilborn said in How to replace a specific text in lines that contains a specific word.:

                              So the (?-s) is a safety-valve on the expression, in this instance saying “everything must be on the same line”.

                              This sentence sums it up clearly, after this one i was sure i understood everything what you just wrote.
                              I don’t know why did you ask whether i understood the \k fully, but i did.
                              In fact everything was simple, what probably confused me, is that i did not catch what did you mean by “following .” i had no idea that by the dot you meant the whole search.

                              Now everything is clear and i even have a greater understanding on some of the things, i read on the notepad++ wiki.
                              Thanks!

                              BS

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

                                @alan-kilborn,

                                You said :

                                You haven’t been very active lately.

                                You’re quite right ! Well, there’s a simple explanation to this :

                                • First of all, at this time of the year, I am rather involved in ski, which is a passion of mine !

                                • Secondly, each Wednesday, with eight other people, we supervise , at the Chamrousse station,( the nearest from Grenoble ) 50 children about, from 5 to 14 years old, in ski lessons, for any level, from Débutants to Flèche de Bronze ( approximatively, from american ski level 1 to 8 : refer, for instance, https://www.tripsavvy.com/skiing-ability-levels-3007976 )

                                • And thirdly, last week-end, we were 13 people at Courchevel, a very well-known French station, with a wonderful sunny and blue weather ! Really, we had lunch, Sunday midday, on the terrace of the hotel and it was rather hot, at about 1700 m !


                                Next Thursday, we’ll be, for the day, at the Karellis station :

                                336bbaaa-1d48-4162-8c0e-e1c9d44c7ba0-Capture d’écran 2022-01-25 122601.png

                                Best regards,

                                guy038

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

                                  @guy038 said in How to replace a specific text in lines that contains a specific word.:

                                  First of all, at this time of the year, I am rather involved in ski, which is a passion of mine !

                                  I’m not an excellent skier, but nothing sounds better to me right now than joining you on those slopes! :-)

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