Home > Software engineering >  RegEx match first paragraph, then rest of paragraphs
RegEx match first paragraph, then rest of paragraphs

Time:11-14

I have a set of paragraphs I want to seperate

Lorem ipsum dolor sit amet, consectetur adipiscing elit, 
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. 
Montes nascetur ridiculus mus mauris vitae ultricies. 
Porttitor eget dolor morbi non arcu risus. Lacus luctus accumsan tortor posuere ac. 
Ac turpis egestas maecenas pharetra convallis posuere morbi.

Purus ut faucibus pulvinar elementum. 
Neque volutpat ac tincidunt vitae semper quis lectus. 
Aliquet sagittis id consectetur purus ut faucibus pulvinar elementum integer. 
Eget gravida cum sociis natoque. Amet est placerat in egestas erat imperdiet sed euismod nisi. 
Rhoncus mattis rhoncus urna neque viverra. 

Morbi enim nunc faucibus a pellentesque sit amet porttitor eget. 
Nullam vehicula ipsum a arcu cursus vitae congue mauris. 
Amet purus gravida quis blandit turpis cursus in. 
Elementum facilisis leo vel fringilla. 

Sed enim ut sem viverra aliquet eget. 
Ac tortor vitae purus faucibus ornare suspendisse sed nisi lacus. 
Risus sed vulputate odio ut. Metus vulputate eu scelerisque felis imperdiet proin. 
Feugiat nisl pretium fusce id. Dui vivamus arcu felis bibendum ut tristique et. 
Blandit turpis cursus in hac habitasse platea dictumst quisque. 

I want to see if it's possible how I can match just the first paragraph then match everything from the second paragraph all the way to the end. I did something like .*?(?=\n|$) but only got the first paragraph. I want to see if there's a way to match both a first paragraph, then the rest from the second paragraph.

CodePudding user response:

You could try using the following pattern:

(.*?)\n{2,}(.*)

Make sure that you run this regex in dot all mode. Here is a working demo.

  • Related