我想将这一行拆分为\n
。
a = "Id, Name, Age, Address\n123,John,23,\"No:23 21st street\n areacode\npincode\"\n124,Antony,25,\"No:213 29th street\n areacode\npincode\"\n"
用\ n分割线后,该线应该是这样的。
a = ["Id, Name, Age, Address", "123,John,23,\"No:23 21st street\n areacode\npincode\"", "124,Antony,25,\"No:213 29th street\n areacode\npincode\"]
我试过的命令
a.scan(/(?!\B"[^"]*)^C?(?:[\n\r]+|\z)(?![^"]*"\B)/)
a.scan(/.+?(?:[\n\r]+|\z)/)
答案 0 :(得分:1)
a = "Id, Name, Age, Address\n123,John,23,\"No:23 21st street\n areacode\npincode\"\n124,Antony,25,\"No:213 29th street\n areacode\npincode\"\n"
a.split "\n"
["Id, Name, Age, Address", "123,John,23,\"No:23 21st street", " areacode", "pincode\"", "124,Antony,25,\"No:213 29th street", " areacode", "pincode\""]