Regexp won't match

后端 未结 2 1865
你的背包
你的背包 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.

提交回复
热议问题