简体   繁体   English

xml schema regex - 如何选择大写字母后跟所有小写字母

[英]xml schema regex - how to select capital letter followed by all lowercase

So I have to following XML elements:所以我必须遵循 XML 元素:

<branch>
    <branchName>Emperor</branchName>
</branch>

and

<branch>
    <branchName>Perception<branchName>
</branch>

.. and so on, all of which start with a capital letter and the rest is lowercase. .. 等等,所有这些都以大写字母开头,其余都是小写字母。 I tried to use Regex to capture this however this is my first time using it an I just throw together the following:我尝试使用 Regex 来捕获它,但是这是我第一次使用它,我只是将以下内容放在一起:

"[A-Z](([a-z])*)"

When I tried to validate my schema using the validator it did not work, I got an error saying:当我尝试使用验证器验证我的架构时,它不起作用,我收到一条错误消息:

ERROR - cvc-pattern-valid: Value 'Emperor' is not facet-valid with respect to pattern '[A-Z](([a-z])*)' for type '#AnonType_branchNamebranchbranches'.
ERROR - cvc-type.3.1.3: The value 'Emperor' of element 'branchName' is not valid.
ERROR - cvc-pattern-valid: Value 'Perception' is not facet-valid with respect to pattern '[A-Z](([a-z])*)' for type '#AnonType_branchNamebranchbranches'.
ERROR - cvc-type.3.1.3: The value 'Perception' of element 'branchName' is not valid.

Essentially I looked at w3schools version of how to restrict data.基本上我查看了如何限制数据的w3schools版本。 After that I looked around for a tutorial for regular expressions but none show how to combine expressions, they just show how you write individual parts.在那之后,我四处寻找正则表达式的教程,但没有展示如何组合表达式,它们只是展示了如何编写各个部分。

1) My question is how do I show this using a regular expression? 1)我的问题是如何使用正则表达式来显示? (An uppercase followed by n number of lower cases) (大写字母后跟 n 个小写字母)

2) could you direct me to a good tutorial that shows from start to end how to create a regular expression for xml 2)你能指导我一个很好的教程,从头到尾展示如何为 xml 创建正则表达式

(An answer to 1 is appreciated but only if 2 is also answered. I do want to learn this for myself) (对 1 的回答表示赞赏,但前提是也回答了 2。我确实想为自己学习这个)

edit 31/03/2016 @ 01:38: Changed the question in order to make what I was asking more clear.编辑 2016 年 3 月 31 日 @ 01:38:更改了问题以使我问的更清楚。

1) My question is how do I show this using a regular expression? 1)我的问题是如何使用正则表达式来显示? (An uppercase followed by n number of lower cases) (大写字母后跟 n 个小写字母)

Using regex like this.像这样使用正则表达式。

Regex: ^[AZ][az]+ .正则表达式: ^[AZ][az]+ If you use * instead of + it will also match is there are zero lower case letters.如果您使用*而不是+它也将匹配zero个小写字母。

Regex101 Demo Regex101 演示

您可以尝试使用 out ^ 它将匹配 aBc 也作为正确的字符串。

^[A-Z][a-z]+ 

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

相关问题 python 正则表达式查找小写字母后跟大写字母 - python regex find lowercase followed by capital letter 小写字母或句点的正则表达式,后跟大写字母 - regex for lowercase letter or period followed by an uppercase letter Python Regex - 检查大写字母后面的大写字母 - Python Regex - checking for a capital letter with a lowercase after R:strsplit中的正则表达式(找到“,”后跟大写字母) - R: Regex in strsplit (finding “, ” followed by capital letter) 匹配大写字母、数字或大写、小写和数字的正则表达式 - Regex to match on capital letter, digit or capital, lowercase, and digit 识别罗马数字后跟“.”、空格和大写字母。 (正则表达式) - Recognize roman numeral followed by '.', space and then capital letter. (RegEx) 正则表达式匹配第一个大写字母,然后是一个或多个小写字母 - Regex matching first capital letter followed by one or more small letters 不允许正则表达式 大写字母后跟小写字母后跟数字后跟特殊字符 - Regex not allowed Capital letter followed by lower case letters followed by number followed by special character 正则表达式查找HTML标记之间的小写字母和大写字母 - Regex to find a lowercase letter followed by an uppercase between a HTML tag 如何使用大写字母替换大写字母后跟一段时间? - How do I replace a capital letter followed by a period with the capital letter only?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM