在javascript中使用大字符串

时间:2015-04-05 15:20:30

标签: javascript regex

说我正在使用以下字符串:

"I know an old lady who swallowed a fly.
I don't know why she swallowed the fly. Perhaps she'll die.

I know an old lady who swallowed a spider.
It wriggled and jiggled and tickled inside her."

我试图根据新行和额外的空间将它们拆分成数组,尝试正则表达式没有用,有什么建议吗?

["I know an old lady who swallowed a fly", "I don't know why she swallowed the fly. Perhaps she'll die.","I know an old lady who swallowed a spider.", "It wriggled and jiggled and tickled inside her."]

1 个答案:

答案 0 :(得分:0)

您可以使用全局和多行标记这样的正则表达式:

/$/gm; 

<强> Working demo

string.split(/$/gm)