gpt4 book ai didi

javascript - RegEx javascript 匹配 2 个连续出现的字符,但不匹配更多

转载 作者:行者123 更新时间:2023-12-02 14:05:56 30 4
gpt4 key购买 nike

我需要正则表达式方面的帮助。我必须匹配字符串开头的“{{”,但不能匹配“{{{”。我尝试使用 ^[{]{2} 但它与“{{{”匹配。我尝试将“{{{”与 ^[^{]{3} 匹配,但我不知道如何再次匹配“{{”。

我知道我可以用 if 语句来解决这个问题。但我想在正则表达式中一次性完成它。有什么想法吗?

最佳答案

Regex101

^{{[^{]^[{]{2}[^{] 都可以

描述

^ asserts position at start of a line
{{ matches the characters {{ literally (case sensitive)
Match a single character not present in the list below [^{]
{ matches the character { literally (case sensitive)

关于javascript - RegEx javascript 匹配 2 个连续出现的字符,但不匹配更多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40033576/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com