我尝试使用制表符,换行符或两者的任意组合或重复来拆分字符串。 例如,一个字符串,例如" A \ tB \ nC \ t \ t \ t \ n \ n \ n \ n \ t \ n \ n \ n \ t \ n \ t"应该回来 一系列" A"," B"等等。到目前为止,我已经能够得到一些结果,但它并不是最佳的:
1 000-00:01:13.221408 6.687540 DATA RUN_BIT
2 000-00:01:28.533108 6.057900 Zbin RUN_BIT
3 000-00:01:41.879568 7.632000 Rbin RUN_BIT
4 000-00:01:55.521768 7.078680 Xbin RUN_BIT
5 000-00:02:09.841308 7.269480 DATA RUN_BIT
6 000-01:02:15.702138 39.419280 DATA RUN_BIT
7 000-01:04:10.840398 70.643700 DATA RUN_BIT
8 000-01:05:21.741678 16.952262 DATA RUN_BIT
9 000-01:06:08.897580 228.587940 DATA RUN_BIT
10 000-01:12:14.890140 17.191080 DATA RUN_BIT
11 000-01:13:38.126640 59.157540 DATA RUN_BIT
12 000-01:14:37.551300 47.337480 DATA RUN_BIT
13 000-01:15:25.155900 66.579024 DATA RUN_BIT
14 000-01:16:32.002044 58.326924 DATA RUN_BIT
15 000-01:17:30.596088 42.328980 DATA RUN_BIT
16 000-01:18:13.182648 13.794840 DATA RUN_BIT
17 000-01:18:27.235068 16.990740 DATA RUN_BIT
18 000-01:18:44.483388 27.179460 DATA RUN_BIT
19 000-01:19:11.929968 34.143660 DATA RUN_BIT
20 000-01:23:00.689628 206.025840 DATA RUN_BIT
21 000-01:26:26.973048 28.791084 DATA RUN_BIT
22 000-01:26:56.021712 58.479564 DATA RUN_BIT
23 000-01:27:54.758856 13.556340 DATA RUN_BIT
我对如何改进它有任何建议。
答案 0 :(得分:2)
试试这个"A\tB\nC\t\tD\n\nE\t\nF\n\tG".split(/\s+/)
答案 1 :(得分:2)
您可以使用此正则表达式/[\r\n\t]+/g
。
"A\tB\nC\t\tD\n\nE\t\nF\n\tG".split(/[\r\n\t]+/g)
//print ["A", "B", "C", "D", "E", "F", "G"]