给定一个没有固定模式的字段分隔符的输入行,如下所示。
x="15:23:46 Let's do this 15:23:47 It's easy: to do for you 15:23:48 You will ## have solution soon 0"
Run Code Online (Sandbox Code Playgroud)
我试图根据时间戳模式在不同的行上打破它,所以预期的输出如下。
15:23:46 Let's do this
15:23:47 It's easy: to do for you
15:23:48 You will have solution soon
0
Run Code Online (Sandbox Code Playgroud)
请注意,行尾有 0 并且也应该打印在换行符上。我需要将它用作其余代码的返回状态。
当时间戳不同时,我能够实现结果,但是当其中一些相同时,就会导致意外输出。
x=" 15:23:46让我们这样做15:23:46很容易:为你做 15:23:48 你很快就会## 有解决方案 0"
请注意,现在我们有两个相同的时间戳。这就是我被困的地方。预期的输出应该是:
15:23:46 Let's do this
15:23:46 It's easy: to do for you
15:23:48 You will have solution soon
0
Run Code Online (Sandbox Code Playgroud)
我使用的逻辑是获取数组中的所有时间戳,然后迭代所需数据的时间戳和 grep 数量。具有唯一时间戳时对我有用的逻辑如下。
15:23:46 Let's do this
15:23:47 It's …Run Code Online (Sandbox Code Playgroud)