[英]Regex Check that each word starts with a capital letter
如果我有这些话
在 Regex 中,我想验证只有数字 3 和 5 有效。 3 是有效的,因为它没有空格并且前面只有 1 个大写字母。 5 是有效的,因为在任何有空格的地方,每个单词都以大写字母开头,没有其他大写字母。 例如 6 无效,因为 Forge 中有一个大写字母 O。
这可以用正则表达式来完成吗?
^(?:\b[A-Z]{1}[a-z]*\b\s?)+$
^ // Start of string
(?: )+ // Capture the following group one or more times
\b // Word boundary
[A-Z]{1} // Exactly one upper case letter
[a-z]* // Zero or more lower case letters
\b // Word boundary
\s? // Zero or one white space character
$ // End of string
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.