使用正则表达式拆分表达式

时间:2014-08-01 16:48:50

标签: regex split

regexp(l,'(\W*+\d{1,3}:\d{1,2})','split')

您好, 这是我的reg exp代码。 这是我的输出

46:28 Corner, Switzerland. Conceded by Walter Ayoví. 46:26 Attempt blocked. Stephan Lichtsteiner (Switzerland) left footed shot from outside the box is blocked. Assisted by Granit Xhaka. 45:00][Second Half begins Switzerland 0, Ecuador 1. 45:00 Substitution]

我想添加量词分割

46:28 Corner, Switzerland. Conceded by Walter Ayoví. 
46:26 Attempt blocked. Stephan Lichtsteiner (Switzerland) left footed shot from outside the box is blocked. Assisted by Granit Xhaka. 
45:00][Second Half begins Switzerland 0, Ecuador 1. 
45:00 Substitution]

接收此类输出

如何在此代码中添加拆分量词,以便在遇到时间字符串(##:##)时从新行开始。

1 个答案:

答案 0 :(得分:1)

我不确定你要分裂的是什么,但这里sed

sed -r s/([0-9][0-9]:[0-9][0-9])/\n\1/g

请注意,这会在第一行之前添加换行符。