Skip to content

Commit

Permalink
Merge pull request #23 from ashbeelghouri/0.5
Browse files Browse the repository at this point in the history
0.4.3
  • Loading branch information
ashbeelghouri committed Jul 6, 2024
2 parents 1d08fbc + c574c2f commit d56820a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions utils/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,21 @@ func StringsInSlice(s []string, slice []string) bool {
return false
}

func IsValidRegex(pattern string) bool {
_, err := regexp.Compile(pattern)
return err == nil
}

func ConvertKeyToRegex(key string) string {
if !IsValidRegex(key) {
return key
}
// Escape special regex characters in the key except for *
escapedKey := regexp.QuoteMeta(key)
// Replace * with \d+ to match array indices
regexPattern := strings.ReplaceAll(escapedKey, `\*`, `\d+`)
// Add start and end of line anchors

regexPattern = "^" + regexPattern + "$"
return regexPattern
}
Expand Down

0 comments on commit d56820a

Please sign in to comment.