Community
    • Login

    Get a word from a file, then use it in a REPLACE, hopefully in one RegEx.

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    3 Posts 2 Posters 121 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
      last edited by

      Given:

      \id NUM kulav.txt 1993 A.Horton.Luvale
      \h KULAVA
      \toc1 Mukanda waKulava
      \toc2 Kulava
      \toc3 Kula
      \mt2 MUKANDA WA
      \mt1 KULAVA
      \c 1
      \s VaIsalele navavalava kuShinai
      \v 1 \nd Yehova\nd* alwezele vaMose naAlone ngwenyi
      \v 2 Lavenu vana vaKohate vamuli vana vaLevi kujita
      \v 3 kuputukila hali vamyaka makumi atatu (30) naku
      \v 4 Eyi yikiko milimo yavana vaKohate vamalunga mu
      \v 5 Omu chilombo nachikakatukanga, kuvanga Alone n
      \s Vana vaLevi navavatongola
      \c 2
      \s Vihela vyajitanga hachilombo
      \v 1 \nd Yehova\nd* alwezele vaMose naAlone ngwenyi
      \v 2 Lavenu vana vaKohate vamuli vana vaLevi kujita
      \v 3 kuputukila hali vamyaka makumi atatu (30) naku
      \v 4 Eyi yikiko milimo yavana vaKohate vamalunga mu
      \v 5 Omu chilombo nachikakatukanga, kuvanga Alone n
      \c 3
      \s Vana vaAlone
      \v 1 \nd Yehova\nd* alwezele vaMose naAlone ngwenyi
      \v 2 Lavenu vana vaKohate vamuli vana vaLevi kujita
      \v 3 kuputukila hali vamyaka makumi atatu (30) naku
      \v 4 Eyi yikiko milimo yavana vaKohate vamalunga mu
      \v 5 Omu chilombo nachikakatukanga, kuvanga Alone n
      \s Milimo yauLevi\f + \fr 3:5 \ft Milimo yauLevi, y
      \s Kusokola vatwatwa
      \c 4
      \s VaLevi\f + \fr 4:1 \ft Milimo yauLevi, yikiko mi
      \v 1 \nd Yehova\nd* alwezele vaMose naAlone ngwenyi
      \v 2 Lavenu vana vaKohate vamuli vana vaLevi kujita
      \v 3 kuputukila hali vamyaka makumi atatu (30) naku
      \v 4 Eyi yikiko milimo yavana vaKohate vamalunga mu
      \v 5 Omu chilombo nachikakatukanga, kuvanga Alone n
      \c 5
      \s Vaze navapihya mwaya Jishimbi
      \v 1 \nd Yehova\nd* alwezele vaMose naAlone ngwenyi
      \v 2 Lavenu vana vaKohate vamuli vana vaLevi kujita
      \v 3 kuputukila hali vamyaka makumi atatu (30) naku
      \v 4 Eyi yikiko milimo yavana vaKohate vamalunga mu
      \v 5 Omu chilombo nachikakatukanga, kuvanga Alone n
      \s Lushimbi lwakuvuluka kushishisa
      \s Lushimbi lwalisungu
      

      This RegEx:

      (?:\\toc2\s)(.+)$
      

      Puts the last word of “\toc2 Kulava” into Group 1.

      I next want to:

      FIND ^\c (\d+) - REPLACE Kulava $1

      Since I already have “Kulava” as $1 in the first above RegEx, is there a way to combine them, and use the $1 from the first as part of the REPLACE in the second?

      Thanx for any and 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 Get a word from a file, then use it in a REPLACE, hopefully in one RegEx.:

        Since I already have “Kulava” as $1 in the first above RegEx, is there a way to combine them, and use the $1 from the first as part of the REPLACE in the second?

        This is very similar to the last solution I gave you.

        Again you:

        1. Reverse the lines
        2. Using Find function with:
          Find What:(?-s)^\\c (\d+)(?=(.*\R)+?\\toc2 (.+)$)
          Replace With:${3} ${1}
          Have the cursor in the first position of the file and click on Replace All.
        3. Reverse the lines

        You seem to think the find and then replacement are two separate process, but in fact it is just 1 as you can see from step #2 above.

        The regular expression is actually performing 2 finds together. The first is the capture of the text which will be replaced. The second find in the same regular expression is a lookahead to find the replacement text, which is used as the replacement of the current capture. This is repeated for every \c line with a following number which is kept.

        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 know this kindness is above and beyond.
          I have been looking, trying to help myself.

          This will save much time and effort.

          Thanx for your patience.

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