简体   繁体   中英

Regex replace line feeds if they occur more than one time including combination with space in between

So i have a string that i want to replace all the line feeds that occur more than two times in a sequence by just one line feed. For this i use:

Regex.Replace(str, "(?:\r\n|\r(?!\n)|(?!<\r)\n){2,}", Environment.NewLine)

This works as long as the sequence is \r\n\r\n but i have a case where is see this \r\n \r\n \r\n So how can i replace those values using Regex?

Regex.Replace(text, @"(?:(?:[ \t\r\n])+(?![\r\n]))+", Environment.NewLine);

Includes tab in addition to space.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM