Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 加拿大邮政编码的正则表达式,允许在前三个字符后使用小写字母或破折号_.net_Regex - Fatal编程技术网

.net 加拿大邮政编码的正则表达式,允许在前三个字符后使用小写字母或破折号

.net 加拿大邮政编码的正则表达式,允许在前三个字符后使用小写字母或破折号,.net,regex,.net,Regex,我想在这个正则表达式中添加小写字符(目前只允许使用大写字母)。我还希望中间的分隔符:“[]”也允许破折号(当前允许有空格或没有空格)。如何使用上述正则表达式来解释这些可能的变化。使用的语言是.net。使用正则表达式构造函数时,请传递 对于第二个要求,将[]?更改为[-]? 总结: ^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$ 知道如何将regexopti

我想在这个正则表达式中添加小写字符(目前只允许使用大写字母)。我还希望中间的分隔符:“[]”也允许破折号(当前允许有空格或没有空格)。如何使用上述正则表达式来解释这些可能的变化。使用的语言是.net。

使用正则表达式构造函数时,请传递

对于第二个要求,将
[]?
更改为
[-]?

总结:

^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$

知道如何将regexoptions添加到数据属性中吗?我正在asp.net mvc中使用模型验证:[正则表达式(^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$,ErrorMessageResourceName=“无效的邮政编码”)@FiveTools只需将(?I放在正则表达式的最开始处,就在前面。
var regex = new Regex(@"^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ -]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$", RegexOptions.IgnoreCase);