回答編集履歴

1

Update

2022/01/18 07:37

投稿

melian
melian

スコア19825

test CHANGED
@@ -4,19 +4,25 @@
4
4
 
5
5
  import (
6
6
  "fmt"
7
+ "index/suffixarray"
7
8
  "regexp"
8
9
  )
9
10
 
10
11
  func main() {
11
- r := regexp.MustCompile(`^//[[:alpha:]]{1,3}fruit$`)
12
+ r := regexp.MustCompile(`//[[:alpha:]]{1,3}fruit`)
12
13
  strings := []string{"//abcfruit", "//abcdfruit", "//a1cfruit"}
13
14
  for _, s := range strings {
15
+ index := suffixarray.New([]byte(s))
16
+ if idx := index.FindAllIndex(r, 1); idx != nil {
14
- fmt.Println(r.MatchString(s), s)
17
+ fmt.Println("Matched", s)
18
+ } else {
19
+ fmt.Println("Not matched", s)
20
+ }
15
21
  }
16
22
  }
17
23
 
18
24
  #
19
- true //abcfruit
25
+ Matched //abcfruit
20
- false //abcdfruit
26
+ Not matched //abcdfruit
21
- false //a1cfruit
27
+ Not matched //a1cfruit
22
28
  ```