my_line = [[this
is
a
test]]
split_file = string.match(my_line, "[^rn]+|^[ tn]*$")
print(#split_file)
上面的代码不起作用,我不知道为什么
string.match(my_line, "[^rn]+")
这是有效的,但它只匹配单词,所以我的数组看起来像这个["this", "is", "a", "test"]
而我希望阵列是
["this", "is", "a", "n", "test"]
不确定您使用的是哪种语言,因此在JavaScript中使用全局(g(和多行(m(标志-
st = `this
is
a
test`;
console.log(JSON.stringify(st.match(/[^rn]+|^[ tn]*/gm))); // ["this","is","a","n","test"]