-
Notifications
You must be signed in to change notification settings - Fork 18k
regexp: regex pattern matching error #52460
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The output should be false, because you are using backquotes `` in the argument to Compile, which makes the argument the literal three bytes '\' '8' 'A', and that's certainly not what you mean. However, changing `` to "" doesn't help, as you can see here: https://go.dev/play/p/mMd57XnQKL6 The argument to Compile must be valid UTF-8, although I'm not sure that's explicitly documented. |
I think this is a bug. If I use the following code, the result is true.
I checked the source code and used the And, If I am wrong, how should I match a character whose ascii is greater than 127? |
Please read https://go.dev/blog/strings for background about how text works in Go as well as in UTF-8. The term "character" is too vague to be technically useful in this context. To answer your direct question, if we assume by "character" you mean "Unicode code point", use a Unicode escape like "\u1234" or write out the bytes of its UTF-8 encoding. Also, \x30 in backquotes is 4 bytes, not one, and none of them is the byte with value 0x30. |
Thank you very much! |
Ha! I'm wrong (as usual, but only a little). The ASCII zero numeral is hexadecimal 30, so my last sentence in my previous reply was incorrect. Still, the overarching point is right: Matching plain bytes won't work in general. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
The output of the test code should be the
true
, however, the output of the console is thefalse
The text was updated successfully, but these errors were encountered: