我想解析以下字符串
3693,"Toxic Avenger,The(1985)",Comedy | Horror
至
3693,
"Toxic Avenger,The(1985)",
Comedy | Horror.
类似地,以下
161944年,美国最后一位制砖厂(2001年),戏剧
应该解析为
161944
美国最后一位制砖厂(2001年)
戏剧
我不能通过逗号分割来实现,因为","中有一个逗号.
工作的解决方案:LS05建议我使用"substring",所以我做了它并且它工作得很完美.这里是.
var pos1 = line.indexOf(',');
var line = line.substring(pos1+1);
pos1 = line.indexOf(',');
pos2 = line.lastIndexOf(',');
let movie_id = line.substring(0,pos1);
let movie_tag = line.substring(pos1+1,pos2);
let movie_timespan = line.substring(pos2+1);
Run Code Online (Sandbox Code Playgroud)
感谢LS05 :)
我有一个字符串:
'"Apples" AND "Bananas" OR "Gala Melon"'
Run Code Online (Sandbox Code Playgroud)
我想将其转换为数组
arr = ['"Apples"', 'AND', '"Bananas"', 'OR', '"Gala Melon"']
Run Code Online (Sandbox Code Playgroud)
我不知道我是否可以用正则表达式来做.我开始认为我可能必须一次解析每个字符以匹配双引号.
喜欢
fetch('state_wise_data.csv')
.then(response => response.json())
.then(data => console.log(data))
.catch(err => console.log(err))
Run Code Online (Sandbox Code Playgroud)
尝试这样做,但没有奏效。
我正在尝试编写正则表达式将字符串拆分为数组.它必须使用空格或逗号的分隔符进行拆分,并忽略引用短语内的分隔符(使用单引号或双引号).
到目前为止,我能够通过空格和逗号分隔它,但是我无法让它在引号之间忽略它们而我已经丢失了.
var pattern = /\b\w+[^"', ]+(?!'")/g,
text = "Hello world \"Boston Red Sox\" hello, world, \'boston, red sox\', \'beached whale\', pickup sticks",
output = text.match(pattern);
Run Code Online (Sandbox Code Playgroud)
当前输出:
["Hello", "world", "Boston", "Red", "Sox", "hello", "world", "boston", "red", "sox", "beached", "whale", "pickup", "sticks"]
Run Code Online (Sandbox Code Playgroud)
期望的输出:
["Hello", "world", "Boston Red Sox", "hello", "world", "boston, red sox", "beached whale", "pickup", "sticks"]
Run Code Online (Sandbox Code Playgroud)
任何帮助都会很棒!