简体   繁体   English

无效的Resx文件。 “ \\”是意外令牌。 预期令牌为“

[英]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 &lt; 由于它是XML文件,因此您需要编码特殊字符,即<变得&lt; , > becomes &gt; >变为&gt; and & becomes &amp; 并且&成为&amp; .

So store it as: 因此将其存储为:

^(?!\\s)(?!.*\\s\\s)[\\x20-\\x7F]{1,35}(?&lt;!\\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}(?&lt;!\s)$</value>
</data>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XmlException: &#39;”&#39; 是一个意外的标记。 预期的标记是 &#39;&quot;&#39; 或 &#39;&#39;&#39; - XmlException: '”' is an unexpected token. The expected token is '"' or ''' &#39;&gt;&#39; 是一个意外的标记。 预期的标记是 &#39;&quot;&#39; 或 &#39;&#39;&#39;。第 1 行,位置 55 - '>' is an unexpected token. The expected token is '"' or '''. Line 1, position 55 未处理XMLException&#39;/&#39;是意外令牌。 预期令牌为“ =”。 4号线,位置18 - XMLException was unhandled '/' is an unexpected token. The expected token is '='. Line 4, position 18 “ Javascript”是意外令牌。 预期令牌为“”或“&#39;&#39;。第5行,第18位 - 'Javascript' is an unexpected token. The expected token is '"' or '''. Line 5, position 18 未处理XMLException&#39;var&#39;是意外令牌。 预期令牌为“ =” - XMLException was unhandled 'var' is an unexpected token. The expected token is '=' System.XML.XmlException:“ ”是意外标记。 预期的令牌是 &#39;;&#39; - System.XML.XmlException: ' ' is an unexpected token. The expected token is ';' System.Xml.XmlException:“[值]”是意外标记。 预期的标记是 '"' 或 ''' - System.Xml.XmlException: '[value]' is an unexpected token. The expected token is '"' or ''' 编码”是意外令牌。 将XML数据读入DataSet时,预期的标记为&#39;?&gt;&#39; - encoding' is an unexpected token. the expected token is '?>' when reading XML data into DataSet 流异常&System.Xml.XmlException:&#39;-&#39;是意外令牌。 预期令牌为” - Stream exception & System.Xml.XmlException: '--' is an unexpected token. The expected token is '' RestSharp Methods抛出System.Xml.XMlException“=”是一个意外的令牌。 预期的标记是&#39;;&#39; - RestSharp Methods Throw System.Xml.XMlException “=” is an unexpected token. The expected token is ';'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM