How do you split a long piece of text into separate lines? Why does this return line1 twice?
/^(.*?)$/mg.exec('line1
line2
');
["line1", "line1"]
I turned on the multi-line modifier to make ^
and $
match beginning and end of lines. I also turned on the global modifier to capture all lines.
I wish to use a regex split and not String.split
because I'll be dealing with both Linux
and Windows
line endings.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…