I am new to golang. I need to remove full stop from end of word but not from floating point. I looked into this post. The python approach r'(?<!\d)\.(?!\d)'
is not exactly applicable in golang so following this cheatsheet, I wrote below
re, err := regexp.Compile("[.$]")
if err != nil {
log.Fatal(err)
}
processedString = re.ReplaceAllString("3.2isgood.", "")
But that doesn't work. Can you please suggest?
I would probably not use regex here, how about strings.Trim here instead? (caveat- would not go through and find any in the middle of the words.)
package main
import (
"fmt"
"strings"
)
func main() {
testCases := []string{
"abc.",
"123.45",
"How about in the middle. Is that ok?",
}
for _, tc := range testCases {
fmt.Println(strings.TrimSuffix(tc, "."))
}
}
Output:
abc
123.45
How about in the middle. Is that ok?