首页 > 解决方案 > Google 表单正则表达式 (REGEX) 逗号分层 (CSV)

问题描述

我有一个包含 1 个或多个 ID 的 Google 表单字段

图案:

允许的例子:

这是我当前的正则表达式(无法正常工作)

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

我究竟做错了什么?

标签: regexgoogle-forms

解决方案


使用您显示的示例,您能否尝试以下操作。

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

上述正则表达式的在线演示

说明:添加上述正则表达式的详细说明。

^(                     ##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.

推荐阅读