package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)(?:\buser1\b)?(.+?)(?:\buser1\b|$)`)
var str = `I don't get how to create a regular expression that matches everything, except a fixed, single word. Can somebody help me?
Background: alias map for mailserver which redirects all mail to one user. /.*/ -> user1 produces a redirection loop, so i need to exclude user1 from the regexp.
Edit:
The regex should match everything, EXCEPT the single word user1. It should also match input that contains that word, i.e., user11.
`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/