此双车把模式在以下情况下不起作用

发布于 2025-01-25 08:47:27 字数 316 浏览 2 评论 0原文

我已经为此创建了正则模式:{{{}} - {{}} - {{}}}}

(?<![^*])(^| [^{^{]) }]*\} \}(?!\})([ - ] {1} \ {\ {\ {[^{}]*\} \} \} \}(?!\}){2}(?! ])

双手柄条重复3次,两者之间的破折号。

但是,以下情况的正则表达式失败了:

- {{}} - {{}}} - {{}}}

ie,即使存在一个dash( - ),该模式也匹配了( - )第一个双车把。理想情况下不应该。

I have created regex pattern for this: {{}}-{{}}-{{}}

(?<![^*])(^|[^{])\{\{[^{}]*\}\}(?!\})([-]{1}\{\{[^{}]*\}\}(?!\})){2}(?![^*])

Double handle bars repeated exactly 3 times with dashes in between.

But the regex pattern is failing for the following case:

-{{}}-{{}}-{{}}

i.e., the pattern is matching even though a dash(-) is present before the first double handlebars. It ideally shouldn't.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓦然回首 2025-02-01 08:47:27

此部分(?在模式末尾的负面lookahead中),

相反,您可以在左侧和右侧主张白色空间边界。

请注意,此部分[ - ] {1}可以写为-

(?<!\S)\{\{[^{}]*\}\}(?:-\{\{[^{}]*\}\}){2}(?!\S)

请参阅a Regex101演示

This part (?<![^*]) means that these should not be a char other than * directly to the left of the current position (which is also used in the negative lookahead at the end of the pattern)

Instead you can assert a whitspace boundary to the left and to the right.

Note that this part [-]{1} can be written as just -

(?<!\S)\{\{[^{}]*\}\}(?:-\{\{[^{}]*\}\}){2}(?!\S)

See a regex101 demo.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文