`too short multibyte code string in regex` 是什么意思?

huangapple go评论69阅读模式
英文:

what does `too short multibyte code string in regex` mean?

问题

我正在创建一个Sublime Text的语法高亮文件。然而,我遇到了一个我不太理解的错误。我有以下的正则表达式:

\x([0-9]|[A-F]|[a-f])([0-9]|[A-F]|[a-f])

当我尝试在Sublime Text中加载这个文件时,我得到了以下错误:

> Error in regex: too short multibyte code string in regex
> \x([0-9]|[A-F]|[a-f])([0-9]|[A-F]|[a-f])

我尝试通过谷歌搜索来理解这个错误的含义,但我只找到了以下相关的链接:

0. rubinius项目的GitHub问题页面

1. stackoverflow的讨论帖

2. Reddit的讨论帖

不幸的是,从这些链接中我只能确定这个错误很可能是由字符编码引起的[来自1和2]。我现在怀疑"\x"可能是问题所在,因为正则表达式中的其他部分都是正确的。如何转义这个字符和其他类似的字符?特别地,是否可以使用一个Golang脚本来清理正则表达式以解决这些问题?

英文:

I am creating a sublime text highlighting file. However, I am stuck with an error I don't fully understand. I have the following regex:

\x([0-9]|[A-F]|[a-f])([0-9]|[A-F]|[a-f])

When I try to load the file in sublime text, I get the error:

> Error in regex: too short multibyte code string in regex
> \x([0-9]|[A-F]|[a-f])([0-9]|[A-F]|[a-f])

I have tried Googling to understand what this error means, the only thing I have come across that is relavent are the following links:

0. github issue of the rubinius project

1. stackoverflow thread

2. reddit thread

Unfortunately, from those links i could only determine that that error likely caused by a character encoding [ from 1 & 2]. I now suspect that "\x" might be the problem as everything else in that regex is fine. How does one escape that character and all others like it, in particular, can a golang script be used to sanitize regexes to get rid of such problems?

答案1

得分: 3

这意味着你忘记在\x中转义\了。
因此,它试图解析形式为\x1234的 Unicode 字符转义,但没有找到足够的数字。

英文:

It means that you forgot to escape the \ in \x.
Therefore, it's trying to parse a Unicode character escape of the form \x1234, and it didn't find enough numbers.

huangapple
  • 本文由 发表于 2015年1月5日 21:58:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/27781076.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定