简体   繁体   中英

Regex to find multiple \n and replace with only one <br/>

I've got a regex .replaceAll("(\\r\\n|\\n)", "< br />")); which replaces all \\n and replaces with < br/> .

The thing I wanted here, is to replace more than one \\n in a row by only one < br/> What would be a regex for that?

添加+量词,表示“一个或多个”:

.replaceAll("(\r?\n)+", "<br />"));

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