【问题标题】:what would be the regex for comma delimited list containing aws security-group包含 aws security-group 的逗号分隔列表的正则表达式是什么
【发布时间】:2023-01-12 20:35:07
【问题描述】:

什么是逗号分隔列表的正则表达式,它可以是空的或者有 aws 安全组,例如sg-qwe12345、sg-543234aewrfs、sg-12eqwrwer、sg-gjkkh12435?

我厌倦了 (^$|sg-[0-9a-z]+,|sg-[0-9a-z]+)(?<!,)$ 在 cloudformation 模板中允许的模式但是当我输入逗号时最后并部署堆栈,堆栈创建过程开始并失败。但理想情况下,它应该停止并要求我检查允许模式中的 (?<!,)$ 不应在末尾使用逗号

【问题讨论】:

    标签: regex amazon-web-services yaml amazon-cloudformation aws-security-group


    【解决方案1】:

    考虑什么是列表“是”是有意义的:

    • 没有
    • 1 项
    • 1项,后跟“分隔符+下一项”,重复0次或多次

    或者,更正式地说:

    list = nil | items
    items = item ( ',' item )*
    item = 'sg-' [0-9a-z]
    

    作为正则表达式,这可能看起来像:

    ^(sg-[0-9a-z]+(,sg-[0-9a-z]+)*)?$
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      相关资源
      最近更新 更多