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 @guy038
      last edited by

      @guy038 Many and much thanx.
      I will give it a whirl!

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

        @guy038
        Getting a colon before Chapters.
        I can remove by another RegEx.
        But if you can help me fix it in your code, that would be great.

        Chapter 3:15	mangana wose mwamufwelela, apwenga n
        :Chapter 4
        
        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:

          I think a RegEx could do this, but I need help.

          This question is almost an exact match for the post #26693 in that it looks like it needs a lookbehind. Of course lookbehinds cannot be variable length so it can’t be achieved.

          As in that post, my solution is to reverse the lines, then the lookbehind becomes a lookahead and can easily be achieved. Lastly the lines are again reversed. These 3 steps can all be recorded as a macro if this is a repeated process.

          So the steps are:

          1. Use Reverse Line Order which is under Edit menu, then Line Operations.
          2. Using the Replace function we have (Have the cursor in the first line of the file):
            Find What:(?-s)^\\v (?=(.+\R)+?(Chapter \d+))
            Replace With:${2}:
            Select Replace All
          3. Use Reverse Line Order which is under Edit menu, then Line Operations.

          Terry

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

            @Terry-R
            Thanx very much!

            1 Reply Last reply Reply Quote 0
            • 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
                                            • First post
                                              Last post
                                            The Community of users of the Notepad++ text editor.
                                            Powered by NodeBB | Contributors