Google 表单正则表达式 (REGEX) 逗号分隔 (CSV)

Google Forms Regular Expressions (REGEX) comma delaminated (CSV)

我有一个 Google 表单字段,其中包含 1 个或多个 ID

模式:

允许的示例:

这是我当前的 REGEX(不能正常工作)

[0-9]{6}[,\s]?([0-9]{6}[,\s])*[0-9]?

我做错了什么?

根据您展示的示例,请您尝试以下操作。

^((?:\d{6})(?:(?:,\s+\d{6}){1,})?)$

Online demo for above regex

解释: 增加对上述正则表达式的详细解释。

^(                     ##Checking from starting of value, creating single capturing group.
   (?:\d{6})           ##Checking if there are 6 digits in a non-capturing group here.
   (?:                 ##Creating 1st non-capturing group here
      (?:,\s+\d{6})    ##In a non-capturing group checking it has comma space(1 or more occurrences) followed by 6 digits here.
   ){1,})?             ##Closing 1st non-capturing group here, it could have 1 or more occurrences of it.
)$                     ##Closing 1st capturing group here with $ to make sure its end of value.

您可以使用

^\d{6}(?:,\s\d{6})*$
  • ^ 字符串开头
  • \d{6}匹配6位数字
  • (?:非捕获组整体重复
    • ,\s\d{6} 匹配 , 一个空白字符和 6 位数字
  • )* 关闭群组并可选择重复
  • $ 字符串结束

Regex demo