使用 korn shell [Version AJM 93u+] 的正则表达式模式用于逗号分隔值

Regex pattern using korn shell [Version AJM 93u+] for comma separated values

我正在尝试在 korn shell 中创建正则表达式模式。我是这个 korn shell 脚本及其正则表达式的新手。

以下情况需要正则表达式:

allowed values如下:

80,01,00
80,00
01
00,80,01,02

not allowed values如下:

 80,   --> with comma in the end.
,01,   --> comma at the start and end.
,00    --> comma at the start.
 8     --> with only one digit
800    --> with three digits 

我试过下面的正则表达式模式:

^(*([0-9][0-9][,])+([0-9][0-9])*([,][0-9][0-9]))$

脚本中的片段如下:

if [[ $END_POINT_LIST =~ ^(*([0-9][0-9][,])+([0-9][0-9])*([,][0-9][0-9]))$ ]]; then
            echo "Input validation passed!"
            export RETURN_CODE=16
            exit 16
        else
            echo "[FATAL] The parameter doesn't match the expected pattern."
            export RETURN_CODE=16
            exit 16
        fi
        ;;

以上正则表达式模式未按预期工作。

我无法找出正则表达式中的错误。

任何指出错误的建议都会有很大帮助。

谢谢!

编辑:

除了@degant 接受的答案外,我想提一下以下内容。

问题中发布的正则表达式的错误是, 字符 * and + 放在 pattern-list 的开头。

如果更改为将 * and + 放在模式列表之后,它就可以正常工作。

下面更正的正则表达式也可以正常工作:

^(([0-9][0-9][,])*([0-9][0-9])+([,][0-9][0-9])*)$

用于匹配以逗号分隔的数字并确保逗号不出现在前面或结尾的正则表达式:

^\d{2}(,\d{2})*$

如果 shell 不支持 \d{2}:

^[0-9][0-9](,[0-9][0-9])*$

Regex101 Demo

编辑: 根据@Doqnach

的建议