Re:Go-Restructure: Sane regular expressions with struct fields
by laumars on Monday January 25, 2016 @10:00AM
(#10967484)
I came to the comments section to ask the same question. I've always liked the idea of reflection but avoided it because of performance scares (and usually I can solve the problem another way).
Since we're discussing the performance footprint of regular expression libraries, it's also worth mentioning how slow even just running the base regexp library can be. For example, the email example could also be written without regex:
indices := strings.Split("[email protected]", "@")
fmt.Println("Name:", indices[0])
fmt.Println("Domain:", indices[1])
Obviously the above code doesn't do any sanity checks - which is where regular expressions can often make things easier. But the above would run a lot faster than a regexp pattern match.
Since we're discussing the performance footprint of regular expression libraries, it's also worth mentioning how slow even just running the base regexp library can be. For example, the email example could also be written without regex:
( https://play.golang.org/p/ZezcoBjc9v )Obviously the above code doesn't do any sanity checks - which is where regular expressions can often make things easier. But the above would run a lot faster than a regexp pattern match.