Brian, The Bikeshed email http://phk.freebsd.dk/sagas/bikeshed/
Regular Expressions: Now You Have Two Problems https://blog.codinghorror.com/regular-expressions-now-you-have-two-problems/ MustCompile is like Compile but panics if the expression cannot be parsed. It simplifies safe initialization of global variables holding compiled regular expressions. https://pkg.go.dev/regexp@go1.19.4#MustCompile You use MustCompile for a local variable. https://go.dev/play/p/WxKPohZhbrE BenchmarkBrianLocal-4 501051 2407 ns/op 797 B/op 12 allocs/op Using MustCompile for a global variable. BenchmarkBrianGlobal-4 1243546 965.9 ns/op 32 B/op 3 allocs/op I used strings.Map. https://go.dev/play/p/F6gNFWjRzGO BenchmarkPeter-4 10065352 111.8 ns/op 16 B/op 1 allocs/op peter On Friday, December 30, 2022 at 6:35:10 AM UTC-5 Brian Candler wrote: > <bikeshed> > https://go.dev/play/p/WxKPohZhbrE > </bikeshed> > > On Thursday, 29 December 2022 at 22:12:47 UTC peterGo wrote: > >> https://go.dev/play/p/F6gNFWjRzGO >> >> >> On Thursday, December 29, 2022 at 12:50:34 PM UTC-5 Mitul sharma wrote: >> >>> Hello, >>> >>> I'm stuck in below code snippet, looking to have a output as string >>> without any digits. >>> Input : "H1e5ll0o" >>> Output: "Hello" >>> >>> I tried with *output := strings.Replace(str, "1", "", -1)*, but it can >>> replace only single digit at a time >>> >>> I'm looking for suggestions for below code snippet , tried to implement >>> a logic where string converted to rune and rune provided >>> as a input to IsDigit(), if it is digit it should replace the digit with >>> "" and print the string , i'm not sure what mistake am i doing in providing >>> parameter >>> and printing output? >>> >>> var output string >>> >>> var r rune >>> for _, r = range input { >>> break >>> } >>> >>> if unicode.IsDigit(rune(r)) { >>> output = strings.Replace(input, "", "", -1) >>> fmt.Println(output) >>> }else{ >>> fmt.Println(input) >>> } >>> >>> >>> >>> On Saturday, 15 January 2011 at 01:31:08 UTC+5:30 Russ Cox wrote: >>> >>>> There is also strings.Map. >>>> >>> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/890564c0-0ed5-46a7-bbfa-ee5ed0cc28ccn%40googlegroups.com.