replace three carriage returns with two
I have a text that has this structure
line1: Sometext(followed by carriage return)
line2: more text(followed by carriage return)
line3: more text(followed by carriage return)
line4: Carriage Return (r)(followed by carriage return)
line5: Carriage Return (r)(followed by carriage return)
line6: new text and so on
How can I replace the three carriage returns in lines (3 through 5) with something else?
I tried
var removeCR: RegExp = /[rn]+/g;
but that did not work. Any ideas. Thank you
str.replace(/[rn]{3}/g, "something else");
Try using the following regex /[rn]{3,}/g
For future reference, I recommend checking out the following website for regex:
https://regex101.com/r/fA3oO3/1
To replace empty lines, you could come up with this:
^$
Apparently, this will only work in multiline
mode.
上一篇: 在c#中将大字符串拆分为更小的块
下一篇: 用两个替换三个回车符