• Login
Community
  • Login

RegEx Help with Backreference I think

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
58 Posts 4 Posters 9.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.
  • R
    Robert Or Janet Diebel @Terry R
    last edited by Mar 18, 2025, 6:54 PM

    @Terry-R
    That is amazing!
    How do I “reverse line order” in a macro?
    Or do I need to have more than one macro, and reverse in between manually?

    T 1 Reply Last reply Mar 18, 2025, 7:00 PM Reply Quote 0
    • T
      Terry R @Robert Or Janet Diebel
      last edited by Mar 18, 2025, 7:00 PM

      @Robert-Or-Janet-Diebel said in RegEx Help with Backreference I think:

      How do I “reverse line order” in a macro?

      In Notepad++ a macro is essentially all the keystrokes (and mouse selections) together with keyboard input recorded. Once saved (and a shortcut can be assigned to it as well), it can be played back. The playing back just replays those keystrokes and mouse selections etc. So yes the reverse line order can also be recorded.

      The online manual has the detail and can explain it much better than I can. You find the link from the ? menu.

      Terry

      R 1 Reply Last reply Mar 18, 2025, 7:06 PM Reply Quote 1
      • R
        Robert Or Janet Diebel @Terry R
        last edited by Mar 18, 2025, 7:06 PM

        @Terry-R
        As I am changing just under 1300 chapters with a lot more than 15 verses, this will save me many hours.
        Your help is much appreciated!
        I will indeed build a macro.

        R 2 Replies Last reply Mar 18, 2025, 7:39 PM Reply Quote 1
        • R
          Robert Or Janet Diebel @Robert Or Janet Diebel
          last edited by Mar 18, 2025, 7:39 PM

          @Robert-Or-Janet-Diebel
          Macro worked great.
          Thanx again!

          1 Reply Last reply Reply Quote 0
          • R
            Robert Or Janet Diebel @Robert Or Janet Diebel
            last edited by Mar 18, 2025, 8:41 PM

            @Robert-Or-Janet-Diebel
            One more thing please.
            The “Chapter” is actually a book name.
            It is the first word in the file. I need that to be read into a variable and put in the beginning of the line instead of the word “Chapter”

            I am working on it, but if you can help that would be appreciated.

            T 1 Reply Last reply Mar 18, 2025, 8:57 PM Reply Quote 0
            • T
              Terry R @Robert Or Janet Diebel
              last edited by Terry R Mar 18, 2025, 9:02 PM Mar 18, 2025, 8:57 PM

              @Robert-Or-Janet-Diebel said in RegEx Help with Backreference I think:

              It is the first word in the file. I need that to be read into a variable and put in the beginning of the line instead of the word “Chapter”

              Well, obviously some examples would be extremely helpful, otherwise I’m just guessing.

              And my first guess would be to have this as the regex:
              (?-s)^\\v (?=(.+\R)+?(.+?\d+$))
              You will see I’ve changed the Chapter<space>\d+ to .+?\d+$. The .+? means to consume characters in a non-greedy fashion and stop when a digit appears. Then the rest says to also consume digits (as many as occurs together) and stop at the end of the line ($). So if there are spaces behind the digits it won’t work. Without examples I can’t be sure.

              Terry

              PS you said first word in the file. So do you really mean it’s the word at the start of each group OR truly ONLY the first line in the file. If ONLY the first line then that is an entirely different sort of regex. Examples with say 2-4 groups of verses. And AGAIN include 2 code boxes, 1st being existing data and 2nd being how you want it to look.

              R 2 Replies Last reply Mar 18, 2025, 9:03 PM Reply Quote 0
              • R
                Robert Or Janet Diebel @Terry R
                last edited by Robert Or Janet Diebel Mar 18, 2025, 9:04 PM Mar 18, 2025, 9:03 PM

                @Terry-R Thanx.
                I need the first word in this file to be used for all “\v”
                The next file will be a different book name and so needs to read the first word, and use it.

                Samu 1
                \v 1:1	Kukuputuka Lizu apwilengako, kah
                \v 1:2	Ikiye apwilenga naKalunga kukupu
                \v 1:3	Vyosena vavitengelele muli Ikiye
                \v 1:4	Muli Ikiye mwapwile Mwono, kaha 
                \v 1:5	Musana kana wamunyika mumilima, 
                \v 1:6	Kwapwile mutu vatumine kufuma ku
                \v 1:7	Ikiye ejile apwenga chinjiho wak
                \v 1:8	Ikiye kapwile Uze Musanako, oloz
                \v 1:9	Musana wamuchano apwile nakwiza 
                \v 1:10	Apwile hakaye, kaha kaye vakaten
                \v 1:11	Ejile kuvyenyi, kaha vaze venyi 
                \v 1:12	Oloze veshovo vamutambwile, vaze
                \v 1:13	vaze vene vásemuwile, keshi kuma
                \v 1:14	Jino Lizu alilingishile Ivene ku
                Samu 2
                \v 1	Halikumbi lyamuchitatu kwapwile chil
                \v 2	Yesu nawa vamusanyikile natumbaji tw
                \v 3	Omu vinyo yahwile, naye alwezele Yes
                
                1 Reply Last reply Reply Quote 0
                • R
                  Robert Or Janet Diebel @Terry R
                  last edited by Mar 18, 2025, 9:07 PM

                  @Terry-R It is the first word, but is repeated for each Chapter

                  R 1 Reply Last reply Mar 18, 2025, 9:11 PM Reply Quote 0
                  • R
                    Robert Or Janet Diebel @Robert Or Janet Diebel
                    last edited by Mar 18, 2025, 9:11 PM

                    @Robert-Or-Janet-Diebel
                    Thanx!
                    That appears to have worked.
                    Wishing you a great day.

                    1 Reply Last reply Reply Quote 0
                    • G
                      guy038
                      last edited by guy038 Mar 18, 2025, 11:12 PM Mar 18, 2025, 11:06 PM

                      Hi, @robert-or-janet-diebel, @terry-r and All,

                      Robert, I’m really sorry because I did a mistake regarding my second and main regex replacement : I mixed two different tests :-((

                      The correct regex S/R was simply :

                      • FIND (?-is)\\v (?=(?s:.+?^(Chapter \d+$)))

                      • REPLACE $1:


                      But, I agree that the @terry-r’s use of the Edit > Line Operations > Reverse Line Order, in order to get the Chapter name after its contents, is quite clever !

                      So, if we use the @terry-r’s method and taking in account your further posts, the task is really simplified :

                      • Run an Edit > Line Operations > Reverse Line order action

                      • Perform the following regex S/R

                        • FIND (?-is)\\v (?=(?s:.+?^(\u[\u\l -]+ \d+$)))

                        • REPLACE $1:

                      • Run again an Edit > Line Operations > Reverse Line order action


                      I used the regex (?-i)\u[\u\l -]+ for the book’s name, just in case you have this kind of title : My very-Best-Novel !

                      BR

                      guy038

                      R 2 Replies Last reply Mar 19, 2025, 3:11 PM Reply Quote 1
                      • R
                        Robert Or Janet Diebel @guy038
                        last edited by Mar 19, 2025, 3:11 PM

                        @guy038 Thanx very much. I am still working on this as the total project requires more changes.

                        All help is appreciated.
                        I am trying to do what I can myself, but am in over my head here.

                        R 1 Reply Last reply Mar 19, 2025, 3:24 PM Reply Quote 0
                        • R
                          Robert Or Janet Diebel @Robert Or Janet Diebel
                          last edited by Mar 19, 2025, 3:24 PM

                          @Robert-Or-Janet-Diebel
                          Adds Book name fine, but all chapters show as “1”

                          R 1 Reply Last reply Mar 19, 2025, 3:35 PM Reply Quote 0
                          • R
                            Robert Or Janet Diebel @Robert Or Janet Diebel
                            last edited by Mar 19, 2025, 3:35 PM

                            @Robert-Or-Janet-Diebel
                            Could be my fault. I am still testing

                            T 1 Reply Last reply Mar 19, 2025, 5:17 PM Reply Quote 0
                            • T
                              Terry R @Robert Or Janet Diebel
                              last edited by Mar 19, 2025, 5:17 PM

                              @Robert-Or-Janet-Diebel
                              Your last few posts aren’t referencing anybody. The @name you use is how to “speak” to a particular poster.

                              The posts are also lacking in detail so it is difficult to know what your problem is.

                              Suggest adding some examples showing before and after the change and what regex you used.

                              Terry

                              R 3 Replies Last reply Mar 19, 2025, 5:52 PM Reply Quote 0
                              • R
                                Robert Or Janet Diebel @Terry R
                                last edited by Mar 19, 2025, 5:52 PM

                                @Terry-R
                                I have, a number of times, needed to grab a Value (usually a book name in this instance)
                                Then I need to fit it into a search as a parameter (maybe as a group) to be used in the Replace.

                                I believe you did that, but I am not sure how.
                                Could you expand a bit one the change you did from “Chapter” to BookName?

                                1 Reply Last reply Reply Quote 0
                                • R
                                  Robert Or Janet Diebel @guy038
                                  last edited by Robert Or Janet Diebel Mar 19, 2025, 6:05 PM Mar 19, 2025, 6:04 PM

                                  @guy038
                                  I have, a number of times, needed to grab a Value (usually a book name in this instance)
                                  Then I need to fit it into a search as a parameter (maybe as a group) to be used in the Replace.

                                  Your FIND did work well,
                                  Thanx.

                                  1 Reply Last reply Reply Quote 1
                                  • R
                                    Robert Or Janet Diebel @Terry R
                                    last edited by Mar 19, 2025, 6:20 PM

                                    @Terry-R I am trying to put together an example.
                                    Will post soon I hope.

                                    1 Reply Last reply Reply Quote 0
                                    • R
                                      Robert Or Janet Diebel @Terry R
                                      last edited by Mar 19, 2025, 7:03 PM

                                      @Terry-R Given:

                                      \id GEN KUPUTUKANEW1, September 18, 2012, LCP LUVALE 
                                      \h KUPUTUKA
                                      \toc1 Mukanda waKuputuka
                                      \toc2 Kuputuka
                                      \toc3 Kupu
                                      \mt2 MUKANDA WA
                                      \mt1 KUPUTUKA
                                      \mt2 MUKANDA WAKAVANGA ÁSONEKELE MOSE
                                      \imt Kujimbula mukanda
                                      \is Ásonekele mukanda
                                      \ip Ou Mukanda waKuputuka vauvulukila Mose ngwavo iki
                                      \ip Mose vamuvulukila kusoneka mikanda yosena yitanu 
                                      \is Mwaka wakuusoneka
                                      \ip Mwaka asonekele Mose uno mukanda wapwile mukachi 
                                      \is Vihande vili mumukanda
                                      \ip Mumukanda waKuputuka mukiko vasoneka haputukilile
                                      \ip MuKuputuka mukiko aputukila Kalunga kulisolola om
                                      \ip Havilongeselo-vyalushiko vitanu navitatu vize vya
                                      \ip Vihande vyamuMukanda waKuputuka vyengila namumuka
                                      \im Unjiho wakuvuluka Mukanda Kuputuka kupwa wamuchan
                                      \is Vihanda vitanu vili mumukanda
                                      \ili1 Kutanga vyamumelu navyahakaye (1:1—2:25)
                                      \ili1 Hafumine kulikanga, nomu Kalunga ashikile ulwil
                                      \ili1 Kulihandununa chambuto yavatu (Kena naAvele), n
                                      \ili1 Kufuma halivaji, nakutwala kuMbavele (8:1—11:9)
                                      \ili1 Kufuma haze Apalama vamusanyikile, nakutwala ku
                                      \c 1
                                      \s Kuputuka chakutanga vyuma
                                      \q1
                                      \v 1 \x + \xo 1:1\xt Yowa 1:1-2\x*Kalunga omu aputuki
                                      \q1
                                      \v 2 Vyahakaye vyapwile kanda visoloke, vyapwile vich
                                      \q1 Milima yafwikile hamwambe.
                                      \q1 Shipilitu\f + \fr 1:2 \ft Eli lizu shipilitu lyap
                                      \s Kutanga mumakumbi atanu nalimwe
                                      \p
                                      \v 3 Jino \x + \xo 1:3\xt Samu 33:6; 2 Koli 4:6\x*Kal
                                      \m
                                      
                                      

                                      How would I grab the word following \toc 2{Space} and use it in the Replace?
                                      FIND - \id.\toc2 (.?)\r\n.*?Kuputuka 1 - REPLACE - Kuputuka 1 - Remove Preamble
                                      This works, but I have to enter the Book Name manually.
                                      Thanx for all help.

                                      T 1 Reply Last reply Mar 19, 2025, 7:22 PM Reply Quote 0
                                      • T
                                        Terry R @Robert Or Janet Diebel
                                        last edited by Mar 19, 2025, 7:22 PM

                                        @Robert-Or-Janet-Diebel said in RegEx Help with Backreference I think:

                                        This works, but I have to enter the Book Name manually.

                                        Well your example is what I’d call the “before” example. How about show the same data but with the changes you’d need to make. As for a book name, I don’t even know where in your example the book name is, it certainly isn’t obvious.

                                        In fact the examples now are looking a lot more complicated than your initial example. That leads me to believe some of the earlier stuff was perhaps made up, and this is the real data. Whilst we are happy to help, I (personally) feel a bit used if it turns out the original solutions weren’t really needed.

                                        If you have a “real” request, please lay it out. We’ve had other posters in the past that “beat about the bush” and only through lots of posts do we realise their actual problem wasn’t the one they initially started with. That is just wasting time and quite frankly can cause friction.

                                        Terry

                                        R 1 Reply Last reply Mar 19, 2025, 7:51 PM Reply Quote 2
                                        • R
                                          Robert Or Janet Diebel @Terry R
                                          last edited by Mar 19, 2025, 7:51 PM

                                          @Terry-R I am truly sorry about this.
                                          There is no attempt to deceive, or use.
                                          And I know you time is valuable by the depth of your responses.
                                          I have a number of macros. They were being executed in a certain order. Your responses help me to think there could be a better way. Maybe doing them in a different order. I am experimenting with that, and will continue.
                                          As stated earlier:
                                          I have, a number of times, needed to grab a Value (usually a book name in this instance)
                                          Then I need to fit it into a search as a parameter (maybe as a group) to be used in the Replace.

                                          The book Name here is “Kuputuka”. I am trying to help some folks who speak the Luvale language.
                                          I need to grab that word, and be able to use it.
                                          I will continue to search.
                                          Your help thus far has moved me forward in understanding some RegEx syntax.
                                          If I can come up with a better example I will post it.
                                          Again, sorry to have troubled you.
                                          Your input has been very much appreciated.

                                          T 1 Reply Last reply Mar 19, 2025, 8:04 PM Reply Quote 0
                                          16 out of 58
                                          • First post
                                            16/58
                                            Last post
                                          The Community of users of the Notepad++ text editor.
                                          Powered by NodeBB | Contributors