0.147652 0.983684 noing_grf 2.316547 3.609503 boing_4r4
到一个有效的 json文件 像这样的对象格式
{ 'noing_grf': { start: 0.147652, end: 0.983684 }, 'boing_4r4': { start: 2.316547, end: 3.609503 }, }
我尝试的模式是这个 ([^\t\n]+) 但我想我需要一个完整的例子来表现。
([^\t\n]+)
任何正则表达式专业人士都能帮我做到这一点,我一点也不成功! 就像这个API。 http://pixijs.io/pixi-sound/examples/sprites.html
您必须使用正则表达式来执行此操作吗? 您可以用javascript(或任何其他编程语言)非常简单地实现这一点。
const data = `0.147652 0.983684 noing_grf 2.316547 3.609503 boing_4r4`; const dictionary = {}; const lines = data.split("\n"); lines.forEach(line => { line = line.split("\t"); dictionary[line[2]] = { start: line[0], end: line[1] }; });
生成的字典将具有所需的格式:
{ noing_grf: { start: '0.147652', end: '0.983684' }, boing_4r4: { start: '2.316547', end: '3.609503' } }