c# - ConfigurationSectionDesigner验证中分号分隔数字字符串的正则表达式?
问题描述
需要对带有分号分隔的 HTTP 状态代码的字符串应用正则表达式验证:
"202;500;503"
我试过这个正则表达式
^([0-9]+;)*[0-9]+$
但我得到一个例外:
属性“retryStatusCodes”的值无效。错误是:该值不符合验证正则表达式字符串^([0-9]+;)*[0-9]+$
。
这怎么可能?我在这里测试过:https ://regexr.com/
它奏效了
为什么它在 C# 代码中不起作用?
我用它来验证 ConfigurationSectionDesigner 中的属性,该属性的自动生成代码:
/// <summary>
/// Gets or sets the RetryStatusCodes.
/// </summary>
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("ConfigurationSectionDesigner.CsdFileGenerator", "2.0.3.2")]
[global::System.ComponentModel.DescriptionAttribute("The RetryStatusCodes.")]
[global::System.Configuration.RegexStringValidatorAttribute("^([0-9]+;)*[0-9]+$")]
[global::System.Configuration.ConfigurationPropertyAttribute(global::XXX.XXX.XXX.RetryStatusCodesPropertyName, IsRequired=true, IsKey=false, IsDefaultCollection=false)]
public virtual string RetryStatusCodes
{
get
{
return ((string)(base[global::XXX.XXX.XXX.RetryStatusCodesPropertyName]));
}
set
{
base[global::XXX.XXX.XXX.RetryStatusCodesPropertyName] = value;
}
}
解决方案
推荐阅读
- reactjs - React Typescript:从本地文本文件中读取
- html - 我需要一些关于 HTML 代码的帮助(输入类型="radio")
- reactjs - 如何在反应js中将rest api调用保留在不同的文件中
- discord - discord.py Ping 命令
- javascript - 按钮 onclick 导致链接
- python - check_hostname 需要 server_hostname
- wordpress - 如何将 /lang 添加到 Wordpress 主页 url?
- python - 为什么替换 DataFrame 中的值也会替换原始 DataFrame 中的值
- spring - Sort.of 中的 Spring 自定义排序
- c++ - 将参数传递给回调函数的最佳方法是什么?(C & C++)