| 2470 | } |
| 2471 | } |
| 2472 | function parseJsonPath(_path) { |
| 2473 | const path = _path.trim() |
| 2474 | const output = [] |
| 2475 | const regex = /\.?([^\.\[\]]+)|\[(['"])(.*?)\2\]|\[(\d+)\]/g |
| 2476 | let match |
| 2477 | |
| 2478 | while ((match = regex.exec(path)) !== null) { |
| 2479 | if (match[1] !== undefined) { |
| 2480 | // 匹配点符号或初始键 |
| 2481 | output.push(match[1]) |
| 2482 | } else if (match[3] !== undefined) { |
| 2483 | // 匹配带引号的括号表示法 |
| 2484 | output.push(match[3]) |
| 2485 | } else if (match[4] !== undefined) { |
| 2486 | // 数组索引,转换为整数 |
| 2487 | output.push(parseInt(match[4], 10)) |
| 2488 | } |
| 2489 | } |
| 2490 | return output |
| 2491 | } |
| 2492 | |
| 2493 | // 解析规则 |
| 2494 | function parseRule(input) { |