I have been able to replicate the OP's problem with go 1.21.0 ==> main.go <== package main
import ( "plugin" //"regexp" "regexp/syntax" ) func main() { //_, _ = regexp.Compile(`\w+`) p, err := plugin.Open("p1.so") if err != nil { panic(err) } s, err := p.Lookup("F") if err != nil { panic(err) } f := s.(func() (syntax.Flags, error)) _, err = f() if err != nil { panic(err) } } ==> p1/plugin.go <== package main import ( "regexp" "regexp/syntax" ) func F() (syntax.Flags, error) { _, err := regexp.Compile(`\w+`) return syntax.Flags(0), err } func main() {} $ go version go version go1.21.0 linux/amd64 $ go build -buildmode=plugin ./p1 && go run main.go panic: error parsing regexp: invalid escape sequence: `\w` goroutine 1 [running]: main.main() /home/ubuntu/62430/main.go:24 +0x129 exit status 2 The problem goes away if you uncomment the two commented-out lines in main.go I had an idea about what might be happening. In this situation, MustCompile is behaving like MustCompilePOSIX (which doesn't accept the \w character class). Package regexp/syntax defines a constant "Perl" which includes various flags, including PerlX which allows this class: func Compile(expr string) (*Regexp, error) { return compile(expr, syntax.Perl, false) } I'm wondering if somehow this value hasn't been initialized, and is treated as zero. However, if I print the value of syntax.Perl within main() or F(), I see that it is 212 as expected, even when the error occurs. On Monday, 4 September 2023 at 18:55:07 UTC+1 Brian Candler wrote: > I'm afraid I have to contradict that answer (from an AI chatbot perhaps?) > > Go's regexp library, called re2, is documented here: > https://github.com/google/re2/wiki/Syntax > > It *does* support the \w character class. See the section headed "Perl > character classes (all ASCII-only)". Furthermore, the OP was successfully > using \w with go 1.20.7. The problem arose with 1.21 and is something to > do with plugin loading or initialization. > > On Monday, 4 September 2023 at 17:56:32 UTC+1 Google's Affiliate (Google > Business Affiliate) wrote: > >> Hello, this is Jonathan, I can help you with your question about the >> error parsing regexp in Go. >> >> The error you are getting is caused by the use of \w in your regular >> expression. This is an invalid escape sequence in Go, because \w is not >> a predefined character class >> <https://stackoverflow.com/questions/6770898/unknown-escape-sequence-error-in-go> >> 1 >> <https://stackoverflow.com/questions/6770898/unknown-escape-sequence-error-in-go> >> . Go only supports the following escape sequences in regular expressions >> <https://www.bing.com/search?form=MY0291&OCID=MY0291&q=Bing+AI&showconv=1#> >> 2 >> <https://stackoverflow.com/questions/24836885/go-regex-error-parsing-regexp-invalid-escape-sequence-k> >> : >> >> - \t for tab >> - \n for newline >> - \r for carriage return >> - \f for form feed >> - \a for alert >> - \b for word boundary >> - \B for non-word boundary >> - \d for decimal digit >> - \D for non-decimal digit >> - \s for whitespace character >> - \S for non-whitespace character >> - \w for word character (alphanumeric plus _) >> - \W for non-word character >> >> To match a word character in Go, you need to use [[:word:]], which is >> equivalent to [0-9A-Za-z_]. Alternatively, you can use [[:alnum:]]_, >> which is equivalent to [0-9A-Za-z]_. So, your regular expression should >> be: >> >> regexp.Compile(`^([[:word:]./]+)/((?:[[:word:]]+)|[*])(.+)?$`) >> >> or >> >> regexp.Compile(`^([[:alnum:]_./]+)/((?:[[:alnum:]_]+)|[*])(.+)?$`) >> >> This should fix the error and allow you to load the plugin successfully. >> >> I hope this helps you with your problem. If you have any further >> questions, please feel free to ask. 😊 >> >> >> >> On Sunday, September 3, 2023 at 4:47:39 AM UTC-4 Olivier Szika wrote: >> >>> Hi, >>> >>> Unexpectedly, unicode.Categories is an empty map when it's only used >>> with a plugin. >>> I opened a ticket: https://github.com/golang/go/issues/62430 >>> >>> Regards, >>> >>> Le samedi 12 août 2023 à 18:13:31 UTC+2, Wojciech S. Czarnecki a écrit : >>> >>>> Dnia 2023-08-08, o godz. 18:11:56 >>>> Bernd Fix <b...@hoi-polloi.org> napisał(a): >>>> >>>> > After switching from go1.20.7 to go1.21.0 one of my applications >>>> > compiles without warnings or errors, but fails at run-time with the >>>> > following panic when loading a plugin: >>>> >>>> IIRC release notes tools now are version aware, so likely you need to >>>> bring >>>> all go.mod's version to state 1.21.0 >>>> >>>> hope this helps, >>>> >>>> > Cheers, Bernd. >>>> > >>>> >>>> -- 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/682cb7ce-142a-478f-ab69-6f5a043ecb36n%40googlegroups.com.