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.
    • guy038G
      guy038
      last edited by

      Hello, @robert-or-janet-diebel,

      Well, I’m terribly sorry because, given your INPUT text provided in your last post, the two search regexes, of your BookAndVerse macro, below, do not get any match ??

      • FIND (?-s)^\\c (\d+)(?=(.*\R)+?\\toc2 (.+)$)

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

      Did you provide the right INPUT text to test against ?

      BR

      guy038

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

        @guy038 Thanx for responding.
        If I run the MACRO to change \c & \v with a number and a word (\toc2 1 Samwele) it fails.
        If I remove the number (\toc2 Samwele) it works. The number and {space} cause failure.
        Could the RegEx be altered to allow the number and {space}?

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

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • Robert Or Janet DiebelR
            Robert Or Janet Diebel @guy038
            last edited by

            @guy038 The MACRO reverses line order.
            I can maybe get the changes done with a number of simpler RegEx’s run after the fact, but I would prefer it totally automated if possible.
            Another alternative is to separate the Numbered books and have a separate RegEx to run against them that would allow a number and {space}

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

              Hi , @robert-or-janet-diebel,

              Oh… How silly I am ! You’re perfectly right. At first sight, I do not remark this important line, beginning your BookAndVerse macro :

                          <Action type="2" message="0" wParam="42083" lParam="0" sParam="" />
              

              So, instead of using the ^\u[\u\l -]+ part, for the name, we can use, either, the regexes :

              • ^\w[\w'’ -]+

              or

              • ^[[:alnum:]][[:alnum:]'’ -]+ IF no LOW LINE character ( \x{005F} ) occurs in the name

              Within these two regexes, I also added the two apostrophe syntaxes ['’]. If you do not need them, don’t add them in the character class !

              So, given this example, below :

              My very-Best-Novel
              1 Samwele
              5 L'été de tous les dangers
              5 L’été de tous les dangers
              1_ te_ST
              
              • The first regex ^\w[\w'’ -]+ would match the five lines above

              • The second regex ^[[:alnum:]][[:alnum:]'’ -]+ would match the first four lines, only


              Thus, If we take the general case, you must change, in your Step 2, the search regex as below :

              • FIND (?-is)\\v (?=(?s:.+?^(\w[\w'’ -]+ \d+$)))

              Best Regards,

              guy038

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

                @guy038 I am so very thankful for your help.
                Sorry I forgot to point out the line order reversal.
                I will give it a try!
                All the best to you and yours.

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

                  @guy038 That is working great! I am so thankful!
                  Dare I mention my last failing MACRO that should change the {space} after the Book-Chapter:verse to a TAB?
                  Same issue, it works if there is no number.
                  I will try to figure it out, but if you have any guidance, it would be appreciated.

                          <Macro name="Space2Tab" Ctrl="no" Alt="no" Shift="no" Key="0">
                              <Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
                              <Action type="3" message="1601" wParam="0" lParam="0" sParam="^(\w+\s\d+:\d+)\s(.*)$" />
                              <Action type="3" message="1625" wParam="0" lParam="2" sParam="" />
                              <Action type="3" message="1602" wParam="0" lParam="0" sParam="$1\t$2" />
                              <Action type="3" message="1702" wParam="0" lParam="512" sParam="" />
                              <Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
                          </Macro>
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • Robert Or Janet DiebelR
                    Robert Or Janet Diebel @guy038
                    last edited by

                    @guy038 Got my space-to-tab working.
                    Thanx for all your help!

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

                      @guy038 Spoke too soon. Got it to change numbered book, then failed on non-numbered.
                      I am still working on it.

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

                        Hello, @robert-or-janet-diebel,

                        I suppose that the following regex S/R should work :

                        • FIND ^([\w ]+\x20\d+:\d+)\x20

                        • REPLACE $1\t

                        Best Regards,

                        guy038

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

                          @guy038 This works on numbered, but not unnumbered.
                          Here is what I tried.

                          ^(\d+?\s?\w+\s\d+:\d+)\s(.*)$
                          

                          It worked on numbered, but not unnumbered
                          I thought the “?” would make it optional.

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

                            @guy038 Sorry, that does work. I somehow slipped in a space before the RegEx in the MACRO

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