Skip to content

Commit

Permalink
🚀 正则表达式匹配,支持负数和小数点 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cairry authored Feb 22, 2025
1 parent f902baf commit c4608e3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion alert/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ func (c *Consume) executeTask(faultCenter models.FaultCenter, taskChan chan stru
// 事件分组
var alertGroups AlertGroups
c.alarmGrouping(faultCenter, &alertGroups, filterEvents)
fmt.Println("alertGroups->", tools.JsonMarshal(alertGroups.Rules))
// 事件聚合
aggEvents := c.alarmAggregation(faultCenter, &alertGroups)
// 发送事件
Expand Down
4 changes: 2 additions & 2 deletions pkg/tools/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func ProcessRuleExpr(ruleExpr string) (string, float64, error) {
// 去除空格
trimmedExpr := strings.ReplaceAll(ruleExpr, " ", "")

// 正则表达式匹配
re := regexp.MustCompile(`([^\d]+)(\d+)`)
// 正则表达式匹配,支持负数和小数点
re := regexp.MustCompile(`([^\d\-]+)(-?\d+(?:\.\d+)?)`)
matches := re.FindStringSubmatch(trimmedExpr)
if len(matches) < 3 {
return "", 0, fmt.Errorf("无效的表达式: %s", ruleExpr)
Expand Down

0 comments on commit c4608e3

Please sign in to comment.