BeH*_*Haa 1 javascript string split
我有一个来自.txt文件的长字符串,其中包含我要分割的几个句子和日期.
语法是这样的
01-01-15: Here is some text
02-01-15: Here is some other text
05-06-17: Here is some new text
06-06-17: Here is some text
taking up
several lines
07-06-17: And so on
Run Code Online (Sandbox Code Playgroud)
由于有些句子占用了几行而我无法使用text.split("\n")- 但我能做些什么呢?所有句子都以xx-xx-xx开头,其中x是数字.
您可以通过使用先行模式搜索每个逻辑单元的开始日期来拆分行.
var data = '01-01-15: Here is some text\
02-01-15: Here is some other text\
05-06-17: Here is some new text\
06-06-17: Here is some text\
taking up \
several lines\
07-06-17: And so on';
console.log(data.split(/(?=\d\d-\d\d-\d\d:)/));Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |