Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

javascript regex detect duplicate blank lines

I tried to detect duplicate blank lines with

\s*\n\n+

https://regex101.com/r/v0imUZ/1

but doesn’t seem to work with

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  test1
   
    
   
   test2
   test3
  test4

  test1
   
    
   
   test2
   test3
  test4

>Solution :

You can use

\n(?:[^\S\n]*\n)+

See the regex demo. If there can be CRLF endings:

\r?\n(?:[^\S\n\r]*\r?\n)+

Details:

  • \r? – an optional carriage return symbol
  • \n – a newline char
  • (?:[^\S\n]*\n)+ – one or more occurrences of
    • [^\S\n]* – zero or more whitespace chars excluding newline char, and then
    • \n – a newline char.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading