根据数字前后的数字匹配句子组(Javascript)



我正试图在我的副本中的/\n[\d-+]*/和/\n\\d-+]//之间提取数据,

我已经接近了,但我的团队正在生成空的"复制

目前我的Regex是:

/(?<!nd[-+]*)(.*?)(?=(nd|$))/sg

在这里演示

下面是我的副本示例。这是一种重复模式,但我对如何让重复小组发挥作用感到困惑。

1 Failure, mutation may not be used again that day, roll on defects table.
2-11 Failure, mutation may not be used again that day.
12-13 The mutant releases a single flash of light that blinds one target for 1d3 rounds (save for half the duration), or optionally the mutant may generate a field of ambient light in a 40’ radius for 1 hour/CL.
14-17 The mutant releases a single flash of light that blinds one target for 1d6 rounds, save for half the duration.
18-19 The mutant releases a single flash of light that blinds up to 6 targets for 1d6 rounds, save for half the duration.
20-23 The mutant releases a series of strobing light pulses that blind and stun up to 6 targets for 1d6 rounds.
24-27 The mutant releases a cascade of dazzling light pulses that hypnotize up to 10 HD of targets for 1d8
rounds (save for half the duration) and places them in a highly suggestible state.
28-29 The mutant’s body releases a gigantic orb of pure photons that deals 6d6 damage to any targets in
a straight path to its final target, blinding anyone looking for 1d10 rounds (save for half damage
and duration).
30-31 The mutant fires a high energy beam of coherent light that permanently blinds one target and causes 8d6
of damage, save for temporary blindness (1d10 turns) and half damage.
32+ The mutant fires a high energy beam of coherent light that permanently blinds one target and causes 10d6
of damage, save for temporary blindness (1d10 days) and half damage; up to four additional adjacent
targets are blinded for 1d10 rounds.

期望的结果是([0]表示输出数组中的每个新组。(

[0] 1 Failure, mutation may not be used again that day, roll on defects table.
[1] 2-11 Failure, mutation may not be used again that day.
[2] 12-13 The mutant releases a single flash of light that blinds one target for 1d3 rounds (save for half the duration), or optionally the mutant may generate a field of ambient light in a 40’ radius for 1 hour/CL.
[3] 14-17 The mutant releases a single flash of light that blinds one target for 1d6 rounds, save for half the duration.
[4] 18-19 The mutant releases a single flash of light that blinds up to 6 targets for 1d6 rounds, save for half the duration.
[5] 20-23 The mutant releases a series of strobing light pulses that blind and stun up to 6 targets for 1d6 rounds.
[6] 24-27 The mutant releases a cascade of dazzling light pulses that hypnotize up to 10 HD of targets for 1d8
rounds (save for half the duration) and places them in a highly suggestible state.
[7] 28-29 The mutant’s body releases a gigantic orb of pure photons that deals 6d6 damage to any targets in
a straight path to its final target, blinding anyone looking for 1d10 rounds (save for half damage
and duration).
[8] 30-31 The mutant fires a high energy beam of coherent light that permanently blinds one target and causes 8d6
of damage, save for temporary blindness (1d10 turns) and half damage.
[9] 32+ The mutant fires a high energy beam of coherent light that permanently blinds one target and causes 10d6
of damage, save for temporary blindness (1d10 days) and half damage; up to four additional adjacent
targets are blinded for 1d10 rounds.

任何帮助都将不胜感激,我觉得我很接近,学到了很多,但真的遇到了困难。非常感谢。

假设每个编号的项目都包含在一行中,那么没有理由在这里不使用简单的字符串分割,例如

var input = `1 Failure, mutation may not be used again that day, roll on defects table.
2-11 Failure, mutation may not be used again that day.
12-13 The mutant releases a single flash of light that blinds one target for 1d3 rounds (save for half the duration), or optionally the mutant may generate a field of ambient light in a 40’ radius for 1 hour/CL.
14-17 The mutant releases a single flash of light that blinds one target for 1d6 rounds, save for half the duration.
18-19 The mutant releases a single flash of light that blinds up to 6 targets for 1d6 rounds, save for half the duration.
20-23 The mutant releases a series of strobing light pulses that blind and stun up to 6 targets for 1d6 rounds.
24-27 The mutant releases a cascade of dazzling light pulses that hypnotize up to 10 HD of targets for 1d8
rounds (save for half the duration) and places them in a highly suggestible state.
28-29 The mutant’s body releases a gigantic orb of pure photons that deals 6d6 damage to any targets in
a straight path to its final target, blinding anyone looking for 1d10 rounds (save for half damage
and duration).
30-31 The mutant fires a high energy beam of coherent light that permanently blinds one target and causes 8d6
of damage, save for temporary blindness (1d10 turns) and half damage.
32+ The mutant fires a high energy beam of coherent light that permanently blinds one target and causes 10d6
of damage, save for temporary blindness (1d10 days) and half damage; up to four additional adjacent
targets are blinded for 1d10 rounds.`;
console.log(input.split(/r?n/));

假设每个项目都有CR?LF内部,你可以通过使用积极的前瞻性使上述拆分更加具体:

console.log(input.split(/r?n(?=s*d+(?:+|-d+))/));

最新更新