Skip to content

Commit

Permalink
escape regex special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
gwirn committed Aug 30, 2023
1 parent 4631522 commit 280a636
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/gwirn/go-local-fuzz
module github.com/gwirn/golaf

go 1.20
11 changes: 9 additions & 2 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,15 @@ func showSearch(pattern, searchString string, inAlgn1, inAlgn2 []rune, color str

if quality >= qualityCutOff {
// search for aligned section in the search string and build regex pattern
inAlgn2Str := string(inAlgn2)
specialRegex := []string{"\\", ".", "+", "*", "?", "^", "$", "(", ")", "[", "]", "{", "}", "|"}
for _, i := range specialRegex {
if strings.Contains(inAlgn2Str, i) {
inAlgn2Str = strings.ReplaceAll(inAlgn2Str, i, fmt.Sprintf("\\%s", i))
}
}
var rePatBuilder strings.Builder
splitAlgn2 := strings.Split(string(inAlgn2), "-")
splitAlgn2 := strings.Split(inAlgn2Str, "-")
partsNum := len(splitAlgn2)
lastPartInd := partsNum-1
for i := 0; i < partsNum; i++ {
Expand Down Expand Up @@ -336,6 +343,6 @@ func main() {
a1, a2 := backtrace(fm, []rune(pattern), []rune(target), []rune{}, []rune{}, mI, mJ, gapPenalty, -3, 3)
reverseRune(a1)
reverseRune(a2)
showSearch(pattern, target, a1, a2, "green", 0.6)
fmt.Println(showSearch(pattern, target, a1, a2, "green", 0.6))
*/
}

0 comments on commit 280a636

Please sign in to comment.