简体   繁体   English

正则表达式,制作基本标题

[英]Regex, Making A Basic Title

I am currently using Regex and I have absolutely no idea how to. 我目前正在使用正则表达式,我完全不知道如何。 I got somewhere with the help of msdn, but not far enough: 我在msdn的帮助下到达了某处,但还不够远:

So below I copied and pasted Regex code that I want to include with another rule I need. 所以下面我复制并粘贴了我想要包含的另一个规则所需的正则表达式代码。 This code below does not allow special characters as well as numbers in the field: 下面的代码不允许特殊字符以及字段中的数字:

[RegularExpression(@"^[a-zA-Z''-'\s]{1,40}$", ErrorMessage = 
        "Numbers and special characters are not allowed in the Title.")]

I need this as well as a restriction on using capital letters after every space. 我需要这个以及在每个空格后使用大写字母的限制。

Example: Every Day I Learn Something New <--Correct 例子:我每天都学到新的东西< - 正确
but not: Every day i learn something new. 但不是:每天我都学到新东西。 <--Incorrect < - 不正确的

Just like making a title for an article. 就像为文章制作标题一样。

If you can help out an uneducated Regex coder that would be much appreciated 如果你可以帮助一个未经教育的正则表达式编码器,将非常感激

Cheers 干杯

([A-Z]+[A-Za-z]*\s+)*

您可以在此站点Regex Tester上测试您的Regex

This question describes how to do negative matches. 此问题描述了如何进行否定匹配。 For your case, you could also require that string match @"^((?!\\s[az]).)*$" . 对于您的情况,您还可以要求字符串匹配@"^((?!\\s[az]).)*$"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM