【发布时间】:2021-11-17 00:36:45
【问题描述】:
我有一些示例字符串需要处理
string1 = "_Wondrous item, common (requires attunement by a wizard or cleric)_"
string2 = "_Weapon (glaive), rare (requires attunement)_"
string3 = "_Wondrous item, common_"
我想将它们分解成以下内容
group1 = {
type: "Wonderous item";
rarity: "common";
attune: True
class: "wizard or cleric"
}
group2 = {
type: "Weapon (glaive)";
rarity: "rare";
attune : True
}
group3 = {
type: "Wondrous item"
rarity: "common"
attune: False
}
我目前拥有的正则表达式很混乱,可能效率低下,但它只会破坏第一个。
regex = /_(?<type>[^:]*),\s(?<rarity>[^:]*)\s\((?<attune>[^:]+)by a(?<class>[^:]*)\)_/U
添加详细信息
- 这将在逐个处理文本文档时使用
- 刺痛将在每个文档中出现一次
- 如果有人好奇,我会在 Obsidian.MD 中使用它和模板工具
- 是的,这是处理从 Reddit 捕获的 D&D 魔法物品
【问题讨论】:
标签: javascript regex markdown