【问题标题】:How can i fix this regex pattern我该如何修复这个正则表达式模式
【发布时间】:2022-12-21 22:41:07
【问题描述】:

我正在使用以下正则表达式来检查以逗号分隔的数字字符串是否匹配。

^\\d+(,\\d+)*$

但是声纳显示以下错误。

Refactor this repetition that can lead to a stack overflow for large inputs.

我怎样才能解决这个问题?

例子

",3"    -> not match
"3,3"   -> match
"3,3,"  -> not match
","     -> not match
"1"     -> match
"a,1"   -> not match

【问题讨论】:

  • 您的正则表达式模式没有任何问题,我建议在 SonarQube 中关闭此规则,或者添加一个例外。

标签: regex sonarqube stack-overflow


【解决方案1】:

你可以使用这个正则表达式^d+(,d+)?$

这是一个example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    相关资源
    最近更新 更多