Related to this, couldn't it also be made case insensitive to simplify it? https://go.dev/play/p/5qJTAcmkowg
On Tue, Feb 14, 2023, 1:51 p.m. Rob Pike <r...@golang.org> wrote: > I suggest two changes. > > First, always use backquotes `` around regular expressions to avoid > misunderstandings should a backslash occur. > > Second, in this case if M|m is just a choice and not a subexpression you > need to track, you can make it easier to read by using character classes to > reduce the number of parentheses. It is easier to read therefore. You will > need to adjust the code that uses subexpression matching. I did this by > hand and didn't test it, but it will give you the idea: > > `([Mm][Pp])[34])|([Ff][Ll][Aa][Cc])$` > > In fact, if you don't need subexpressions there are no parentheses needed, > as the alternation operator groups as you would expect. > > `[Mm][Pp][34]|[Ff][Ll][Aa][Cc]$` > > However, I suspect at least some of the elements must be parenthesized for > the job at hand. > > -rob > > > On Wed, Feb 15, 2023 at 2:51 AM Howard C. Shaw III <howardcs...@gmail.com> > wrote: > >> var ExtRegex = >> regexp.MustCompile("(M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$") >> >> with a >> ./prog.go:10:18: >> regexp.MustCompile("((M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$") (value of >> type *regexp.Regexp) is not constant >> >> >> Actual error I get is "error parsing regexp: unexpected ): >> `(M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$`" >> It is missing a parentheses. This compiles fine: >> >> var ExtRegex = >> regexp.MustCompile("((M|m)(p|P)(3|4))|((F|f)(L|l)(A|a)(C|c))$") >> Note that there are two parentheses after the double-quote. >> >> -- >> 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/a5acd2a9-d0a7-4bd0-8712-13f5f0fbbbb6n%40googlegroups.com >> <https://groups.google.com/d/msgid/golang-nuts/a5acd2a9-d0a7-4bd0-8712-13f5f0fbbbb6n%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> > -- > 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/CAOXNBZR-bjiA3w%2BK4_fdTucRBO9LXXjQj28qzaJzmdVUDNGSJg%40mail.gmail.com > <https://groups.google.com/d/msgid/golang-nuts/CAOXNBZR-bjiA3w%2BK4_fdTucRBO9LXXjQj28qzaJzmdVUDNGSJg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- 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/CAFbKU6yve-9ZLt44HW3zPumLfONRPUEsnGgp-DXx-vM2fuJ37g%40mail.gmail.com.