[英]Invalid Resx file. '\' is an unexpected token. The expected token is '<!--' or '<[CDATA['
I was trying to put regular expression in Resx file which is an xml file. 我试图将正则表达式放入XML文件Resx文件中。 But when I add the expressions, it is giving the following error.
但是当我添加表达式时,它给出了以下错误。
Invalid Resx file. '\' is an unexpected token. The expected token is '<!--' or '<[CDATA['
The reg expression is reg表达式是
^(?!\s)(?!.*\s\s)[\x20-\x7F]{1,35}(?<!\s)$
Thanks. 谢谢。
As it is an XML file, you need to encode special characters, ie <
become <
由于它是XML文件,因此您需要编码特殊字符,即
<
变得<
, >
becomes >
,
>
变为>
and &
becomes &
并且
&
成为&
. 。
So store it as: 因此将其存储为:
^(?!\\s)(?!.*\\s\\s)[\\x20-\\x7F]{1,35}(?<!\\s)$
The default Managed Resources Editor inside Visual Studio is able to escape every character for you. Visual Studio中的默认托管资源编辑器可以为您转义每个字符。 You should be able to copy your regex into it without problems.
您应该可以将正则表达式复制到其中,而不会出现问题。
If you then open your regex file in plain text you see something along those lines: 如果您随后以纯文本格式打开正则表达式文件,则会看到以下内容:
<data name="foo" xml:space="preserve">
<value>^(?!\s)(?!.*\s\s)[\x20-\x7F]{1,35}(?<!\s)$</value>
</data>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.