Known unknown escape sequence in Go

1,475 views
Skip to first unread message

Tong Sun

unread,
Mar 22, 2018, 6:33:18 PM3/22/18
to golang-nuts
I'm trying with simple Perl character class regular expression, which should be supported by Go (link)

However, I'm getting "unknown escape sequence" errors. 
I'm wondering why, and how to make it works. 

The code is at,

and I found that `\w` or `\S` Perl character class are not supported. 

please help

$ go version
go version go1.8.3 linux/amd64

andrey mirtchovski

unread,
Mar 22, 2018, 7:00:37 PM3/22/18
to Tong Sun, golang-nuts
the backslash character means something within double quotes. either
escape it ("\S" becomes "\\S") or use backquotes (`\S`)
> --
> 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...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Lutz Horn

unread,
Mar 23, 2018, 3:49:10 AM3/23/18
to golan...@googlegroups.com
> I'm trying with simple Perl character class regular expression, which
> should be supported by Go (link)
[...]
> and I found that `*\w*` or `*\S*` Perl character class are not supported.

You must escape the backslash as '\\w' etc:

https://play.golang.org/p/EEudvWCX_i6

Lutz
Reply all
Reply to author
Forward
0 new messages