Community
    • 登入

    Change location of the forward slash in every row containing 1 NAME

    已排程 已置頂 已鎖定 已移動 Help wanted · · · – – – · · ·
    5 貼文 2 Posters 2.0k 瀏覽
    正在載入更多貼文
    • 從舊到新
    • 從新到舊
    • 最多點贊
    回覆
    • 在新貼文中回覆
    登入後回覆
    此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
    • HVNFH
      HVNF
      最後由 編輯

      In a very large file I want to change the location of the forward slash to the beginning of the last word in the sentence for every row starting with “1 NAME”

      Example before
      1 NAME Hylkje /Eelkes Bouma/

      Example after
      1 NAME Hylkje Eelkes /Bouma/

      Can this be done with Notepad++

      PeterJonesP 1 條回覆 最後回覆 回覆 引用 0
      • PeterJonesP
        PeterJones @HVNF
        最後由 編輯

        @HVNF said in Change location of the forward slash in every row containing 1 NAME:

        Can this be done with Notepad++

        Yes.

        One such way would be

        • FIND = (?-s)^1 NAME.*\K/((?:\S+\h+)+)
        • REPLACE = $1/
        • Search Mode = Regular Expression

        This looks for lines starting with 1 NAME followed by something, followed by / and one or more words-then-spaces. It uses a regex trick \K to “reset” the match so we don’t have to grab the first part of the line into memory. It puts the words+spaces into group1 memory. The replacement then puts group 1 before the slash instead of after.

        There are lots of other ways to do it. And depending on other data, and how accurately your samples represented your whole, this may-or-may-not work out-of-the-box.

        Good luck.

        ----

        Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.

        1 條回覆 最後回覆 回覆 引用 2
        • HVNFH
          HVNF
          最後由 編輯

          @PeterJones said in Change location of the forward slash in every row containing 1 NAME:

          (?-s)^1 NAME.*\K/((?:\S+\h+)+)

          Thank you very much for the fast reaction and it worked…
          But… in the result i see i did not asked the right question, my fault.
          People with surnames with "van der"in front of it are missing the “van der” part.

          Example
          1 NAME Janke /Pieters van der Meer/

          Became:
          1 NAME Janke Pieters van der /Meer/

          This should be:
          1 NAME Janke Pieters /van der Meer/

          So I should have asked for the question:
          Can the slash be moved to the beginning of the next word?

          PeterJonesP 1 條回覆 最後回覆 回覆 引用 0
          • PeterJonesP
            PeterJones @HVNF
            最後由 編輯

            @HVNF said in Change location of the forward slash in every row containing 1 NAME:

            People with surnames with "van der"in front of it are missing the “van der” part.

            There is no regular expression which magically can tell the difference between a multi-word name where the “last name” is just the last token and a multi-word name where the “last name” includes spaces like van der Meer. You could try to add in exceptions into the single regex, but that’s fragile and hard to maintain.

            What I might do is start the process by doing a series of replacements like van\x20der\x20 => van☺der☺ for all your exceptions – using some non-space character like the smiley in the replacement (\x20 is an alternate way of writing a space character in the search and replace expressions). Then run the procedure I described. Then change the ☺ back to a space.

            But if you really want the slash to just move forward one word instead of to the last word, then just get rid of the last + in the expression: (?-s)^1 NAME.*\K/((?:\S+\h+)) – that way, it only looks to move one word and its spaces, rather than all the words and their spaces.

            If any of your names have middle names, then the move-forward-one-rule won’t work for you.

            Names are hard. And regex aren’t the best tool for parsing names. Good luck.

            1 條回覆 最後回覆 回覆 引用 2
            • HVNFH
              HVNF
              最後由 編輯

              Thank you very much!
              I used your last resolution: Find: (?-s)^1 NAME.*\K/((?:\S+\h+)) and replace with $1/
              it worked perfect!

              For people searching for this, i used it for batch editing a raw gedcom com familytree file.
              In older familytree software the firstname patronym and surname was noted differently so in a modern gedcom file the patronym would end op in the surname field.
              using notepad++ you can edit the raw gedcom file and with find and replace you can move the slash from the patronym to the surname.
              In this case it was a lifework from an old geneologist of 170.000 persons in a gedcom which was almost obsolete if this was not solved.
              Peter Jones thank you very much.

              1 條回覆 最後回覆 回覆 引用 3
              • 第一個貼文
                最後的貼文
              The Community of users of the Notepad++ text editor.
              Powered by NodeBB | Contributors