javascript - JS regex to split by line -
how split long piece of text separate lines? why return line1 twice?
/^(.*?)$/mg.exec('line1\r\nline2\r\n'); ["line1", "line1"]
i turned on multi-line modifier make ^ , $ match beginning , end of lines. turned on global modifier capture all lines.
i wish use regex split , not string.split because i'll dealing both linux \n , windows \r\n line endings.
arrayoflines = linestring.match(/[^\r\n]+/g); as tim said, both entire match , capture. appears regex.exec(string) returns on finding first match regardless of global modifier, wheras string.match(regex) honouring global.
Comments
Post a Comment