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



  • 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


  • @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



  • 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


Log in to reply