.net 加拿大邮政编码的正则表达式,允许在前三个字符后使用小写字母或破折号
我想在这个正则表达式中添加小写字符(目前只允许使用大写字母)。我还希望中间的分隔符:“[]”也允许破折号(当前允许有空格或没有空格)。如何使用上述正则表达式来解释这些可能的变化。使用的语言是.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
[]?
更改为[-]?
总结:
^[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);