Skip to content

Commit 05588f7

Browse files
authored
Merge pull request kubernetes#82928 from chendotjs/simplify-regex
simplify regexp with raw string
2 parents 3698100 + 3175c9e commit 05588f7

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

hack/conformance/check_conformance_test_requirements.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ import (
3232

3333
const (
3434
//e.g. framework.ConformanceIt("should provide secure master service ", func() {
35-
patternStartConformance = "framework.ConformanceIt\\(.*, func\\(\\) {$"
36-
patternEndConformance = "}\\)$"
37-
patternSkip = "framework.Skip.*\\("
35+
patternStartConformance = `framework.ConformanceIt\(.*, func\(\) {$`
36+
patternEndConformance = `}\)$`
37+
patternSkip = `framework.Skip.*\(`
3838
)
3939

4040
// This function checks the requirement: it works for all providers (e.g., no SkipIfProviderIs/SkipUnlessProviderIs calls)
@@ -82,7 +82,7 @@ func checkAllProviders(e2eFile string) error {
8282
}
8383

8484
func processFile(e2ePath string) error {
85-
regGoFile := regexp.MustCompile(".*\\.go")
85+
regGoFile := regexp.MustCompile(`.*\.go`)
8686

8787
files, err := ioutil.ReadDir(e2ePath)
8888
if err != nil {

pkg/kubectl/cmd/get/customcolumn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
utilprinters "k8s.io/kubectl/pkg/util/printers"
3737
)
3838

39-
var jsonRegexp = regexp.MustCompile("^\\{\\.?([^{}]+)\\}$|^\\.?([^{}]+)$")
39+
var jsonRegexp = regexp.MustCompile(`^\{\.?([^{}]+)\}$|^\.?([^{}]+)$`)
4040

4141
// RelaxedJSONPathExpression attempts to be flexible with JSONPath expressions, it accepts:
4242
// * metadata.name (no leading '.' or curly braces '{...}'

pkg/util/ebtables/ebtables.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func getEbtablesVersionString(exec utilexec.Interface) (string, error) {
110110
if err != nil {
111111
return "", err
112112
}
113-
versionMatcher := regexp.MustCompile("v([0-9]+\\.[0-9]+\\.[0-9]+)")
113+
versionMatcher := regexp.MustCompile(`v([0-9]+\.[0-9]+\.[0-9]+)`)
114114
match := versionMatcher.FindStringSubmatch(string(bytes))
115115
if match == nil {
116116
return "", fmt.Errorf("no ebtables version found in string: %s", bytes)

pkg/util/iptables/iptables.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ func makeFullArgs(table Table, chain Chain, args ...string) []string {
573573
return append([]string{string(chain), "-t", string(table)}, args...)
574574
}
575575

576+
const iptablesVersionPattern = `v([0-9]+(\.[0-9]+)+)`
577+
576578
// getIPTablesVersion runs "iptables --version" and parses the returned version
577579
func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversion.Version, error) {
578580
// this doesn't access mutable state so we don't need to use the interface / runner
@@ -581,7 +583,7 @@ func getIPTablesVersion(exec utilexec.Interface, protocol Protocol) (*utilversio
581583
if err != nil {
582584
return nil, err
583585
}
584-
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
586+
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
585587
match := versionMatcher.FindStringSubmatch(string(bytes))
586588
if match == nil {
587589
return nil, fmt.Errorf("no iptables version found in string: %s", bytes)
@@ -641,7 +643,7 @@ func getIPTablesRestoreVersionString(exec utilexec.Interface, protocol Protocol)
641643
if err != nil {
642644
return "", err
643645
}
644-
versionMatcher := regexp.MustCompile("v([0-9]+(\\.[0-9]+)+)")
646+
versionMatcher := regexp.MustCompile(iptablesVersionPattern)
645647
match := versionMatcher.FindStringSubmatch(string(bytes))
646648
if match == nil {
647649
return "", fmt.Errorf("no iptables version found in string: %s", bytes)

0 commit comments

Comments
 (0)