正则表达式:如何忽略 [Y](X) 模式中的嵌套括号?
Regex: how to ignore nested brackets in [Y](X) pattern?
我正在使用正则表达式来查找和替换类似于此模式的文本部分:
[Y](X)
其中 X 和 Y 是不同的短语,
并且搜索过程仅基于 X
以下模式可以完成这项工作,但它会替换更多文本
当有嵌套括号时
\[.*\]\(X\)
例如
[ZZZ [Y](X)
文本示例:
The [epidermis](Epidermis (skin)) (the outermost layer of skin) and the outer dermis (the layer beneath the epidermis).Contact dermatitis results in large, burning, and itchy rashes. These can take anywhere from several days to weeks to heal. This differentiates it from contact urticaria –
如何修复我的正则表达式以避免这种情况?
如果我理解正确的话,你想像这样使用积极的展望:
在此示例中:
[epidermis](Epidermis (skin))
你做这样的事情:
\[[^\[\]]*?\](?=\(Epidermis \(skin\)\))
我正在使用正则表达式来查找和替换类似于此模式的文本部分:
[Y](X)
其中 X 和 Y 是不同的短语, 并且搜索过程仅基于 X
以下模式可以完成这项工作,但它会替换更多文本 当有嵌套括号时
\[.*\]\(X\)
例如
[ZZZ [Y](X)
文本示例:
The [epidermis](Epidermis (skin)) (the outermost layer of skin) and the outer dermis (the layer beneath the epidermis).Contact dermatitis results in large, burning, and itchy rashes. These can take anywhere from several days to weeks to heal. This differentiates it from contact urticaria –
如何修复我的正则表达式以避免这种情况?
如果我理解正确的话,你想像这样使用积极的展望:
在此示例中:
[epidermis](Epidermis (skin))
你做这样的事情:
\[[^\[\]]*?\](?=\(Epidermis \(skin\)\))