• Login
Community
  • Login

Add a carriage return \r and linefeed \n to the beginning of a sentence using a regular expression without replacing the text

Scheduled Pinned Locked Moved General Discussion
3 Posts 3 Posters 9.2k 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.
  • M
    Michael Poplawski
    last edited by Feb 19, 2018, 5:49 PM

    The Following text has a carriage return (\r) and line feed (\n) after certain sentences or paragraphs.
    As can be seen in the following text, paragraph 28. has space before the paragraph.
    Paragraph 29 does not have space at the beginning of the sentence.
    I want to use Regular Expressions in notepad++ to find these sentences then add a \r\n to the beginning of sentences that do not have any space.

    I don’t want to replace the text found; just find the paragraph marker and add carriage return / line feed to the beginning.

    Here is my regular expression in the Find what box:
    [\r\n]{1}+[\d]{1,2}.\s\w

    My pseudocode is as follows:
    find the single carriage return / line feed, followed by 1 or 2 digit number, followed by period, followed by space, following by single character.

    I don’t know what to enter in the Replace with box?

    Any help is greatly appreciated.

    inequality and income inequality go hand in hand. In many EMDCs, low-income households and available financial products tend to be more limited and relatively costly.

    IV. INEQUALITY DRIVERS

    A. Factors Driving Higher Income Inequality

    1. Global trends: the good side of the story. Over the past four decades, technology has reduced the costs of transportation, improved automation, and communication dramatically. New markets have opened, bringing growth opportunities in countries rich and poor alike, and hundreds of millions of people have been lifted out of poverty. However, inequality has also risen, possibly
      reflecting the fact that growth has been accompanied by skill-biased technological change, or
      because other aspects of the growth process have generated higher inequality. In this section, we
      discuss potential global and country-specific drivers of income inequality across countries.
    2. Technological change. New information technology has led to improvements in
      productivity and well-being by leaps and bounds, but has also played a central role in driving up the
      skill premium, resulting in increased labor income inequality (Figure 15). This is because
      technological changes can disproportionately raise the demand for capital and skilled labor over
      low-skilled and unskilled labor by eliminating many jobs through automation or upgrading the skill
    S 1 Reply Last reply Feb 19, 2018, 6:26 PM Reply Quote -1
    • S
      Scott Sumner @Michael Poplawski
      last edited by Scott Sumner Feb 19, 2018, 6:26 PM Feb 19, 2018, 6:26 PM

      @Michael-Poplawski

      Not sure why this was downvoted…are regex questions becoming hated here? I guess I can see that, although they don’t bother me (like HTML/CSS questions do!)

      Anyway, to try and help without reading too much into what you really want (or maybe I am), try:

      Find what zone: ([^\r\n]\R)(\d\d?\.\s.)
      Replace with zone: \1\r\n\2

      1 Reply Last reply Reply Quote 0
      • G
        guy038
        last edited by Feb 19, 2018, 8:21 PM

        Hi, michael-poplawski, @Scott-sumner and All,

        Just a variant of the Scott’s solution :

        SEARCH [^\r\n](?=\R\h*\d+\.\h+)

        REPLACE $0\r\n


        Notes :

        • The searched string is, essentially, the part [^\r\n], which represents any single character, different from, either, the Carriage Return and the New Line characters

        • But the regex engine will consider this match ONLY IF the positive look-ahead (?=\R\h*\d+\.\h+), ending this regex, is true. That is to say, IF it is, immediately followed with a Line Break ( \R ), some horizontal blank characters, even 0 ( \h* ), at least one digit ( \d+ ), then a literal dot ( \. ) and, finally, at least, one horizontal blank character ( \h+ )

        • If this condition is true, in replacement, that single character is, simply, rewritten, due to the $0 syntax, with represents the overall match, and followed by the usual \r\n sequence, which defines a Windows line-break !

        Best Regards,

        guy038

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