How do I do a case insensitive regular expression in Go?

You can set a case-insensitive flag as the first item in the regex.

You do this by adding "(?i)" to the beginning of a regex.

reg, err := regexp.Compile("(?i)"+strings.Replace(s.Name, " ", "[ \\._-]", -1))

For a fixed regex it would look like this.

r := regexp.MustCompile(`(?i)CaSe`)

For more information about flags, search the
regexp/syntax package documentation
(or the syntax documentation)
for the term “flags”.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)