gpt4 book ai didi

google-cloud-firestore - Firestore 安全规则正则表达式

转载 作者:行者123 更新时间:2023-12-04 21:59:09 29 4
gpt4 key购买 nike

我正在尝试评估 string Firestore 安全规则 基于 matches正则表达式功能

我的代码是 username.matches('^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$')
在线使用正则表达式模拟器它正在工作

https://regex101.com/r/bDXMg3/2/

但是在安全规则中使用相同的语法会引发大量错误

enter image description here

然后我尝试对每个 . 进行双重转义

使用代码 username.matches('^(?!\\.)(?!_)(?!.*\\.$)(?!.*?\\.\\.)[a-z0-9_.]+$')
它只显示一个错误(开头的红色 ^ 符号),但随后它给了我以下错误

enter image description here

Invalid regular expression pattern. Pattern: ^(?!\.)(?!_)(?!.*\.$)(?!.*?\.\.)[a-z0-9_.]+$.

我的目标是:
  • 不以 . 开头或 _
  • 不以 . 结尾
  • 不允许两个 .连续
  • 只有小写 letter charactersnumbers

  • 谁能让我知道我做错了什么?

    最佳答案

    答案在以下来自 Wiktor Stribiżew 的链接中

    If it is really RE2 that is parsing this pattern, then it is clear - it does not support lookaheads/lookbehinds.



    使用 '^[a-z0-9][a-z0-9_]*([.][a-z0-9_]+)*$'
    Google RE2 Regex Escaping periods and underscores error

    关于google-cloud-firestore - Firestore 安全规则正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51848621/

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