Community
    • Login

    RegEx Help with Backreference I think

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    58 Posts 4 Posters 1.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.
    • Robert Or Janet DiebelR
      Robert Or Janet Diebel @Terry R
      last edited by

      @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?

      Terry RT 1 Reply Last reply Reply Quote 0
      • Terry RT
        Terry R @Robert Or Janet Diebel
        last edited by

        @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

        Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 1
        • Robert Or Janet DiebelR
          Robert Or Janet Diebel @Terry R
          last edited by

          @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.

          Robert Or Janet DiebelR 2 Replies Last reply Reply Quote 1
          • Robert Or Janet DiebelR
            Robert Or Janet Diebel @Robert Or Janet Diebel
            last edited by

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

            1 Reply Last reply Reply Quote 0
            • Robert Or Janet DiebelR
              Robert Or Janet Diebel @Robert Or Janet Diebel
              last edited by

              @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.

              Terry RT 1 Reply Last reply Reply Quote 0
              • Terry RT
                Terry R @Robert Or Janet Diebel
                last edited by Terry R

                @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.

                Robert Or Janet DiebelR 2 Replies Last reply Reply Quote 0
                • Robert Or Janet DiebelR
                  Robert Or Janet Diebel @Terry R
                  last edited by Robert Or Janet Diebel

                  @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
                  • Robert Or Janet DiebelR
                    Robert Or Janet Diebel @Terry R
                    last edited by

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

                    Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 0
                    • Robert Or Janet DiebelR
                      Robert Or Janet Diebel @Robert Or Janet Diebel
                      last edited by

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

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

                        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

                        Robert Or Janet DiebelR 2 Replies Last reply Reply Quote 1
                        • Robert Or Janet DiebelR
                          Robert Or Janet Diebel @guy038
                          last edited by

                          @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.

                          Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 0
                          • Robert Or Janet DiebelR
                            Robert Or Janet Diebel @Robert Or Janet Diebel
                            last edited by

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

                            Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 0
                            • Robert Or Janet DiebelR
                              Robert Or Janet Diebel @Robert Or Janet Diebel
                              last edited by

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

                              Terry RT 1 Reply Last reply Reply Quote 0
                              • Terry RT
                                Terry R @Robert Or Janet Diebel
                                last edited by

                                @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

                                Robert Or Janet DiebelR 3 Replies Last reply Reply Quote 0
                                • Robert Or Janet DiebelR
                                  Robert Or Janet Diebel @Terry R
                                  last edited by

                                  @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
                                  • Robert Or Janet DiebelR
                                    Robert Or Janet Diebel @guy038
                                    last edited by Robert Or Janet Diebel

                                    @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
                                    • Robert Or Janet DiebelR
                                      Robert Or Janet Diebel @Terry R
                                      last edited by

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

                                      1 Reply Last reply Reply Quote 0
                                      • Robert Or Janet DiebelR
                                        Robert Or Janet Diebel @Terry R
                                        last edited by

                                        @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.

                                        Terry RT 1 Reply Last reply Reply Quote 0
                                        • Terry RT
                                          Terry R @Robert Or Janet Diebel
                                          last edited by

                                          @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

                                          Robert Or Janet DiebelR 1 Reply Last reply Reply Quote 2
                                          • Robert Or Janet DiebelR
                                            Robert Or Janet Diebel @Terry R
                                            last edited by

                                            @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.

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