Regexp won't match

后端 未结 2 1843
你的背包
你的背包 2021-01-29 16:35

I am trying the following code

d := []byte(\"\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x80J\\x13\\x80SQ\\x80L\\xe0\\x80@\\x92\\x80L?\\x80H\\xe0\")         


        
相关标签:
2条回答
  • 2021-01-29 17:10

    When you use \ in a string, it signals an escape character sequence. The string itself does not appear as \x01..., but instead, each of these chunks is converted into a single character.

    That is to say that your regex is attempting to match the unprocessed string's value and not the actual string value stored in d.

    I'm not sure how to improve your regular expression since it isn't clear to me what you expect it to match. Currently, it appears that you are attempting to validate that the byte array was instantiated using a specific method instead of by setting bytes to integers. If you can better articulate the aim of your regex, I may be able to provide assistance further.

    0 讨论(0)
  • 2021-01-29 17:16

    Look at the different kinds of string literals in the Go documentation.

    You probably want to use the back-ticks (`) for a "raw_string_lit" in your first string.

    0 讨论(0)
提交回复
热议问题