Community
    • Login

    Create macros

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    12 Posts 3 Posters 678 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.
    • PeterJonesP
      PeterJones @victor
      last edited by PeterJones

      @victor ,

      Your text has some strange edge cases that make it really difficult to do – specifically, having the same emdash — as the prefix that you want to put a newline before, and the range-indicator in a range of dates.

      I would recommend breaking it into small, manageable pieces:

      1. Temporarily change date ranges to <####::####>
        FIND = \(\h*(\d+)\h*—\h*(\d+)\h*\)
        REPLACE = <$1::$2>
        SEARCH MODE = Regular Expression
        ⇒ find literal set of parentheses, which have dates separated by an emdash, with optional spaces; capture each date into group 1 and 2. Replace with
      2. Any remaining series of digits followed by ) will be moved to a new line (unless it’s at the beginning of a line):
        FIND = (?<!^)\d+\)
        REPLACE = \r\n$0
        SEARCH MODE = Regular Expression
        ⇒ the (?<!^) says only match when the ###) isn’t the start of the line already; the rest just looks for digits followed by a close-paren.
      3. Any remaining — get prefixed with newline
        FIND = —
        REPLACE = \r\n—
        SEARCH MODE = Regular Expression

        FIND = \h*—\h*
        REPLACE = \r\n—\x20
        SEARCH MODE = Regular Expression
      4. Convert the temporary <####::####> back into (yyyy — yyyy) format with consistent spacing
        FIND = <(\d+)::(\d+)>
        REPLACE = \($1 — $2\)
        SEARCH MODE = Regular Expression

      (yes, with clever regex, steps 2 and 3 could be combined… but I like doing things in smaller meaningful chunks, and each step was complicated enough as it is)

      ----

      Useful References

      • Please Read Before Posting
      • Template for Search/Replace Questions
      • Formatting Forum Posts
      • Notepad++ Online User Manual: Searching/Regex
      • FAQ: Where to find other regular expressions (regex) documentation

      —
      update: I changed step 3 to make it also clean up the spaces after the emdash when it inserts the newlines; the \x20 in the replacement inserts a space (because if I had ended the regex with a space, you probably wouldn’t have noticed it was there; if you want to use an actual space character in your own REPLACE, go ahead.)

      Paunescu MariusP 1 Reply Last reply Reply Quote 2
      • Paunescu MariusP
        Paunescu Marius @PeterJones
        last edited by Paunescu Marius

        @PeterJones said in Create macros:

        ⇒ the (?<!^) says only match when the ###) isn’t the start of the line already; the rest just looks for digits followed by a close-paren.

        It is a way to not put break-lines after ###)? I mean I don’t want to have break lines after digits followed by a close-paren.

        PeterJonesP 1 Reply Last reply Reply Quote 0
        • PeterJonesP
          PeterJones @Paunescu Marius
          last edited by PeterJones

          @Paunescu-Marius said in Create macros:

          It is a way to not put break-lines after ###)? I mean I don’t want to have break lines after digits followed by a close-paren.

          It doesn’t put it after. It puts it before, which is what I thought you wanted.

          In your post, you had all the original data (Text 1) on one line, but the Text 2 (what you wanted) had each numbered line on a separate line. my sequence did that for you.

          Further, I specifically put in the check to make sure it wouldn’t put in a second newline, if the digits-then-close-paren was at the beginning of a line.

          victorV Paunescu MariusP 2 Replies Last reply Reply Quote 0
          • victorV
            victor @PeterJones
            last edited by PeterJones

            @PeterJones
            I used your macros on an OCR text (1)
            The result is in the text (2) and it’s not good
            I’d like it to look like text (3)

            text (1)

            ORIZONTAL: 1) Folclorist de formație hașdeiană (1850—1909), care a coordonat apariția colecției „Materialuri folclorice" (voi. 1 și II, 1712 p.), ce conține peste 4.000 de poezii populare culese- din 27 județe ale țării—Militant pentru, dezvoltarea învățămintului rural din Maramureș (1846—1917), care are meritul de a fi făcut din cercetarea folclorică un mijloc de afirmare națională, a românilor din Transilvania; adună circa 800 de poezii și proverbe, întocmind volumul „Poezii populare -din Maramureș" (1908). 2) Doctor in filologie (1972) eu teza „Teatrul popular de Aiiul nou in Moldova", întocmită pe baza a circa 1 600 texte de teatru popular. A publicat culegerile „Teatrul folcloric din județele Bacău și Neamț" (1968), „Teatrul folcloric din județul Iași" (1969) etc. 3) Liviu Oprea—Folclorist român (1879—1966), colaborator la „Floarea darurilor", „Ion Creangă" etc., care a debutat cu lucrarea „Ritmul muncii în poeziile populare"; a publicat prelucrări de basme și snoave („La șezătoare", „Aliman Voinicul", „La gura sobei" etc.). 4) Folclorist (1828—1908), autor al unei colecții de 85 de basme, legende și snoave, adunate de la un țăran român din Bazna. în 1925 a publicat cu-' iegerea „Basme și legende românești din
            Ardeal"— Vase sanguine—La călușari și la plugușor! 5) Folcloristă (1864 — 1929), una’ din reprezentantele cele mai entuziaste ale vechii școli folcloristice care a înflorit in Moldova între anii 1870—1890; lucrarea care o consacră este „Nunta la români", studiu istorico-etnografic comparatist distins în 1888 de Academia Română cu premiul „Ion Ileliade Rădulescu"—Smiceaua din mărul-dulumăr pe care Petrea Voinicul o duce la zină, în basmul „Petrea Voinicul și Ileana Cosințana" de Sbie-ra.
            

            text (2)

            ORIZONTAL: 
            1) Folclorist de formație hașdeiană (1850 — 1909), care a coordonat apariția colecției „Materialuri folclorice" (voi. 1 și II, 1712 p.), ce conține peste 4.000 de poezii populare culese- din 27 județe ale țării
            — Militant pentru, dezvoltarea învățămintului rural din Maramureș (1846 — 1917), care are meritul de a fi făcut din cercetarea folclorică un mijloc de afirmare națională, a românilor din Transilvania; adună circa 800 de poezii și proverbe, întocmind volumul „Poezii populare -din Maramureș" (
            1908). 
            2) Doctor in filologie (
            1972) eu teza „Teatrul popular de Aiiul nou in Moldova", întocmită pe baza a circa 1 600 texte de teatru popular. A publicat culegerile „Teatrul folcloric din județele Bacău și Neamț" (
            1968), „Teatrul folcloric din județul Iași" (
            1969) etc. 
            3) Liviu Oprea
            — Folclorist român (1879 — 1966), colaborator la „Floarea darurilor", „Ion Creangă" etc., care a debutat cu lucrarea „Ritmul muncii în poeziile populare"; a publicat prelucrări de basme și snoave („La șezătoare", „Aliman Voinicul", „La gura sobei" etc.). 
            4) Folclorist (1828 — 1908), autor al unei colecții de 85 de basme, legende și snoave, adunate de la un țăran român din Bazna. în 1925 a publicat cu-' iegerea „Basme și legende românești din
            Ardeal"
            — Vase sanguine
            — La călușari și la plugușor! 
            5) Folcloristă (1864 — 1929), una’ din reprezentantele cele mai entuziaste ale vechii școli folcloristice care a înflorit in Moldova între anii 1870
            — 1890; lucrarea care o consacră este „Nunta la români", studiu istorico-etnografic comparatist distins în 1888 de Academia Română cu premiul „Ion Ileliade Rădulescu"
            — Smiceaua din mărul-dulumăr pe care Petrea Voinicul o duce la zină, în basmul „Petrea Voinicul și Ileana Cosințana" de Sbie-ra. 
            

            text (3)

            ORIZONTAL: 
            1) Folclorist de formație hașdeiană (1850—1909), care a coordonat apariția colecției „Materialuri folclorice" (voi. 1 și II, 1712 p.), ce conține peste 4.000 de poezii populare culese din 27 județe ale țării
            — Militant pentru, dezvoltarea învățămintului rural din Maramureș (1846—1917), care are meritul de a fi făcut din cercetarea folclorică un mijloc de afirmare națională, a românilor din Transilvania; adună circa 800 de poezii și proverbe, întocmind volumul „Poezii populare -din Maramureș" (1908). 
            2) Doctor in filologie (1972) cu teza „Teatrul popular de Anul nou in Moldova", întocmită pe baza a circa 1 600 texte de teatru popular. A publicat culegerile „Teatrul folcloric din județele Bacău și Neamț" (1968), „Teatrul folcloric din județul Iași" (1969) etc. 
            3) Liviu Oprea
            — Folclorist român (1879—1966), colaborator la „Floarea darurilor", „Ion Creangă" etc., care a debutat cu lucrarea „Ritmul muncii în poeziile populare"; a publicat prelucrări de basme și snoave („La șezătoare", „Aliman Voinicul", „La gura sobei" etc.). 
            4) Folclorist (1828—1908), autor al unei colecții de 85 de basme, legende și snoave, adunate de la un țăran român din Bazna. în 1925 a publicat culegerea „Basme și legende românești din Ardeal"
            — Vase sanguine
            — La călușari și la plugușor! 
            5) Folcloristă (1864 — 1929), una din reprezentantele cele mai entuziaste ale vechii școli folcloristice care a înflorit in Moldova între anii 1870—1890; lucrarea care o consacră este „Nunta la români", studiu istorico-etnografic comparatist distins în 1888 de Academia Română cu premiul „Ion Ileliade Rădulescu"
            — Smiceaua din mărul-dulumăr pe care Petrea Voinicul o duce la zină, în basmul „Petrea Voinicul și Ileana Cosințana" de Sbie-ra.
            

            —

            moderator added code markdown around text; please don’t forget to use the </> button to mark example text as “code” so that characters don’t get changed by the forum

            PeterJonesP 1 Reply Last reply Reply Quote 0
            • Paunescu MariusP
              Paunescu Marius @PeterJones
              last edited by

              This post is deleted!
              1 Reply Last reply Reply Quote 0
              • PeterJonesP
                PeterJones @victor
                last edited by

                @victor ,

                Formatting

                Please use the </> button when you are inserting example text.

                c51a5d01-f971-4f08-b479-8675c6348627-image.png

                This will put in the dummy block in your post:

                ```
                code_text
                ```
                

                Then you can paste your example text over top the code_text that was auto-inserted.

                This prevents the Forum from trying to turn your 1) and 2) into a numbered HTML list, which ruins the data for copy/paste. It will also make sure the forum doesn’t change normal "ASCII quotes" into “Smart Quotes”, and other similar changes.

                I tried to indicate this when I used moderator powers to edit your first post (and now I’ve used moderator powers to edit your next one, too). And I tried to indicate it by linking to the references on how to format forum posts and how to ask search/replace questions, but you didn’t seem to notice that advice. Please pay attention to this advice in the future.

                Quality of Data

                You said,

                2) Doctor in filologie (
                1972) eu teza „Teatrul popular de Aiiul nou in Moldova", întocmită pe baza a circa 1 600 texte de teatru popular. A publicat culegerile „Teatrul folcloric din județele Bacău și Neamț" (
                1968), „Teatrul folcloric din județul Iași" (
                1969) etc. 
                

                Your original example data didn’t show any example dates that had only one year, rather than a range of years. If your original example data had shown an example that had just (1972) as a single date, then I would have noticed it formatted oddly, and could have developed the regex that would have worked for that data.

                When you are asking someone to develop a regex for you, you need to supply a good range of data, otherwise exceptions like that will not be handled right, because we cannot read your mind. A regex is only as good as the example data. This advice was given in the Template for Search/Replace Questions, which I already linked you to.

                OCR

                I used your macros on an OCR text

                Good luck with that. OCR has a tendency to use different characters for the same actual symbol. It will surprise me if it doesn’t sometimes use an ASCII hyphen - , sometimes use an endash – , and sometimes use an emdash — like you showed in the example data.

                Any regex, or sequence of regex, that is run on inconsistent data like you’ve shown will never be 100% correct. You will always have to apply your human brain to the results, and double-check to make sure that everything meets your expectations. (I’ve read some books that were scanned from early 1900s print books and gone through OCR, and republished for free as e-books because they are no longer in copyright; the number of obvious typos that would have been solved if they’d just had one person actually read the entire book through once after the OCR but before publishing was unbelievable.)

                Updated Answer

                Add a Step1b between step1 and step2:

                • FIND = \(\h*(\d+)\h*\h*\)
                  REPLACE = <$1>
                  SEARCH MODE = Regular expression
                  ⇒ similar to step 1, but finds when there’s a single year between open and close parentheses

                Add a step4b after step4:

                • FIND = <(\d+)>
                  REPLACE = \($1\)
                  SEARCH MODE = Regular Expression

                That fixes the (1972) style dates.

                Finally, add a step 5 at the end:

                • FIND = \h*\R(?!\R|—|\d+\)|\Z)
                  REPLACE = \x20
                  SEARCH MODE = Regular Expression
                  ⇒ This looks for any newline that is not followed by another newline, or the dash, or the number-paren prefix, or the end of the file, and replaces it with a space. In other words, this fixes the fact that the Ardeal" of line 4) from your example data was on a separate row in the OCR data, but you don’t seem to want it in a separate row in your text 3 output. If there are other weird exceptions, this might not be sufficient.
                victorV 1 Reply Last reply Reply Quote 1
                • victorV
                  victor @PeterJones
                  last edited by

                  @PeterJones said in Create macros:

                  Please use the </> button when you are inserting example text.

                  I’m so sorry about it
                  I promise to be the last time

                  1 Reply Last reply Reply Quote 0
                  • victorV
                    victor
                    last edited by

                    @PeterJones
                    Millions of thanks
                    you save me a lot of time, a lot of work .
                    Respect
                    Have a nice day !

                    1 Reply Last reply Reply Quote 1
                    • victorV
                      victor
                      last edited by victor

                      Hello Peter !
                      I need your help again, because there are new situations

                      I want text 1 to look like text 2

                      Can you help me?

                      text 1

                       
                      ORIZONTAL: 1) Supranumele lui Alexandru cel Mare (356
                      — 323 î.e.n.), cel mai mare comandant de oști al antichității, care n-a pregetat să-și sacrifice si pe cei mai apropiați generali ai săi, în frunte'cu Clithus și Parmenion, pentru că nu erau de acord cu unele din hotărîrile sale
                      — Rege al Epicului (c. 295
                      — 272 î.e.n.) care, după victoria scump plătită de la Ausculum (279 î.e.n.), a spus: „Încă o victorie ca aceasta si sînt pierdut". 
                      2) Istoric și om politic, roman (c. 55
                      — c. 
                      120). care în „Istoria" sa povestește despre patrioata germană Velleda
                      — Adept și propovăduitor al ideilor lui Jan Hus, care prezentîndu-se în fața Conciliului din Constanța pentru a-și apăra prietenul, va fi și el ars pe rug, ca „eretic" (m. 
                      1416). 
                      3) Filozof idealist grec (469
                      — 399 î.e.n.) care, fiind condamnat la moarte, 
                      4) Battle of New Orleans took place in Chalmette Plantation Louisiana battlefield on January 8, 1815.
                      — Commander of the British Army  (1856—1895).
                      5) City sacked by the Mongols in 1258, marking the end of the Abbasid Caliphate.
                      — Month the Battle of New Orleans ended 
                      6) Pirate who helped with the battle
                      — American Commander, who also became 7th president  (1767—1845) 
                      7) Amount of time after the treaty
                      — City where the battle is being fought
                      — Name of the Peace treaty
                      — River that the battle was on 
                      8) Folclorist de formație hașdeiană  (1850—1909), care a coordonat apariția colecției „Materialuri folclorice" (voi. 1 și II, 1712 p.), ce conține peste 4.000 de poezii populare culese- din 27 județe ale țării
                      — Militant pentru, dezvoltarea învățămintului rural din Maramureș  (1846—1917), care are meritul de a fi făcut din cercetarea folclorică un mijloc de afirmare națională, a românilor din Transilvania; adună circa 800 de poezii și proverbe, întocmind volumul „Poezii populare -din Maramureș" (1908). 
                      11) Doctor in filologie (1972) eu teza „Teatrul popular de Aiiul nou in Moldova", întocmită pe baza a circa 1 600 texte de teatru popular. A publicat culegerile „Teatrul folcloric din județele Bacău și Neamț" (1968), „Teatrul folcloric din județul Iași" (1969) etc. 
                      12) Liviu Oprea
                      — Folclorist român  (1879—1966), colaborator la „Floarea darurilor", „Ion Creangă" etc., care a debutat cu lucrarea „Ritmul muncii în poeziile populare"; a publicat prelucrări de basme și snoave („La șezătoare", „Aliman Voinicul", „La gura sobei" etc.). 
                      VERTICAL:1) Folclorist  (1828—1908), autor al unei colecții de 85 de basme, legende și snoave, adunate de la un țăran român din Bazna. în 1925 a publicat culegerea „Basme și legende românești din Ardeal"
                      — Vase sanguine
                      — La călușari și la plugușor! 
                      2) Folcloristă  (1864—1929), una’ din reprezentantele cele mai entuziaste ale vechii școli folcloristice care a înflorit in Moldova între anii 1870
                      — 1890; lucrarea care o consacră este „Nunta la români", studiu istorico-etnografic comparatist distins în 1888 de Academia Română cu premiul „Ion Ileliade Rădulescu"
                      — Smiceaua din mărul-dulumăr pe care Petrea Voinicul o duce la zină, în basmul „Petrea Voinicul și Ileana Cosințana" de Sbiera.
                      PeterJonesP 1 Reply Last reply Reply Quote 0
                      • victorV
                        victor
                        last edited by victor

                        text 2

                        ORIZONTAL: 
                        1) Supranumele lui Alexandru cel Mare (356 — 323 î.e.n.), cel mai mare comandant de oști al antichității, care n-a pregetat să-și sacrifice si pe cei mai apropiați generali ai săi, în frunte cu Clithus și Parmenion, pentru că nu erau de acord cu unele din hotărîrile sale
                        — Rege al Epicului (c. 295 — 272 î.e.n.) care, după victoria scump plătită de la Ausculum (279 î.e.n.), a spus: „Încă o victorie ca aceasta si sînt pierdut".
                        2) Istoric și om politic, roman (c. 55 —c. 120) care în „Istoria" sa povestește despre patrioata germană Velleda
                        — Adept și propovăduitor al ideilor lui Jan Hus, care prezentîndu-se în fața Conciliului din Constanța pentru a-și apăra prietenul, va fi și el ars pe rug, ca „eretic" (m. 1416).
                        3) Filozof idealist grec (469 — 399 î.e.n.) care, fiind condamnat la moarte,
                        4) Battle of New Orleans took place in Chalmette Plantation Louisiana battlefield on January 8, 1815.
                        — Commander of the British Army (1856 — 1895).
                        5) City sacked by the Mongols in 1258, marking the end of the Abbasid Caliphate.
                        — Month the Battle of New Orleans ended 
                        6) Pirate who helped with the battle
                        — American Commander, who also became 7th president (1767— 1845) 
                        7) Amount of time after the treaty 
                        — City where the battle is being fought
                        — Name of the Peace treaty 
                        — River that the battle was on
                        8) Folclorist de formație hașdeiană (1850—1909), care a coordonat apariția colecției „Materialuri folclorice" (vol. I și II, 1712 p.), ce conține peste 4.000 de poezii populare culese din 27 județe ale țării
                        — Militant pentru, dezvoltarea învățămintului rural din Maramureș (1846—1917), care are meritul de a fi făcut din cercetarea folclorică un mijloc de afirmare națională, a românilor din Transilvania; adună circa 800 de poezii și proverbe, întocmind volumul „Poezii populare din Maramureș" (1908). 
                        11) Doctor in filologie (1972) cu teza „Teatrul popular de Anul nou in Moldova", întocmită pe baza a circa 1 600 texte de teatru popular. A publicat culegerile „Teatrul folcloric din județele Bacău și Neamț" (1968), „Teatrul folcloric din județul Iași" (1969) etc. 
                        12) Liviu Oprea
                        — Folclorist român (1879—1966), colaborator la „Floarea darurilor", „Ion Creangă" etc., care a debutat cu lucrarea „Ritmul muncii în poeziile populare"; a publicat prelucrări de basme și snoave („La șezătoare", „Aliman Voinicul", „La gura sobei" etc.). 
                        VERTICAL:
                        1) Folclorist (1828—1908), autor al unei colecții de 85 de basme, legende și snoave, adunate de la un țăran român din Bazna. în 1925 a publicat culegerea „Basme și legende românești din Ardeal"
                        — Vase sanguine
                        — La călușari și la plugușor! 
                        2) Folcloristă (1864 — 1929), una’ din reprezentantele cele mai entuziaste ale vechii școli folcloristice care a înflorit in Moldova între anii 1870—1890; lucrarea care o consacră este „Nunta la români", studiu istorico-etnografic comparatist distins în 1888 de Academia Română cu premiul „Ion Ileliade Rădulescu"
                        — Smiceaua din mărul-dulumăr pe care Petrea Voinicul o duce la zină, în basmul „Petrea Voinicul și Ileana Cosințana" de Sbiera.```
                        1 Reply Last reply Reply Quote 0
                        • PeterJonesP
                          PeterJones @victor
                          last edited by

                          @victor said in Create macros:

                          I need your help again, because there are new situations

                          What about my previous solution doesn’t work for this one? What have you tried, what did it do, and what about the results didn’t match your desires? It’s not “help” if I just do all the work for you.

                          ----

                          Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

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