Javascript 查找并换行包含换行符的字符串

Javascript 查找并换行包含换行符的字符串,javascript,regex,Javascript,Regex,考虑以下字符串: You look away whilst I weave needles through my skin to seal the scars, running repairs, not alterations. 它实际上以以下形式存储在数据库中: You look away whilst I weave needles\r\n through my skin to seal the scars,\r\n running repairs, not alterations.\r\

考虑以下字符串:

You look away whilst I weave needles
through my skin to seal the scars,
running repairs, not alterations.
它实际上以以下形式存储在数据库中:

You look away whilst I weave needles\r\n
through my skin to seal the scars,\r\n
running repairs, not alterations.\r\n
如何在span标记中查找并包装最后两行?e、 g

You look away whilst I weave needles
<span>through my skin to seal the scars,
running repairs, not alterations.</span>
目前我有:

let regex = new RegExp(stringToMatch,'m'); //I thought 'm', multiline might work?
poem = poem.replace(regex, '<span>' + stringToMatch + '</span>')

它适用于不包含任何字符串的字符串。\r\n.

我建议您使用类似的内容

var poem = 'You look away whilst I weave needles\r\nthrough my skin to seal the scars,\r\nrunning repairs, not alterations.\r\n';
let regex = /((.+[\r\n]+)+)((.+[\r\n]+){2})/
poem = poem.replace(regex, '$1<span>$3</span>');