需要Hard Regex的帮助

技术标签: PHP.  正则表达式  资本化

我需要一个正则表达式,检查字符串是否仅包含字母(A-Z)并且第一个字母为大写,您不能在大写字母中有2个字母,如:托马斯或托马斯但托马斯安德森(Thomas Anderson也是有效的

看:

The Magician Of The Elfs 会有效但不是 ThE MaGiCiAN oF ThE ELFS

if (!preg_match("??", $name)) {
   echo "Invalid name!";
}

希望你能理解!

Tomasz.

无效的:

MaGIciaN Of The ELFz
THomas anderson

有效的:

Magician of the elfs
Magician Of the Elfs
Magician of The elfs
Thomas Anderson
Thomas anderson

基本上我不希望它有可能在一个单词中拥有超过1个大写字母,而不是句子。

看答案

您也可以通过它描述该角色 Unicode字符属性:

/^\p{Lu}\p{Ll}*(?:\s+\p{Lu}\p{Ll}*)*$/

编辑    由于您更改了您的要求,请尝试使用此正则表达式:

/^[\p{Lu}\p{Ll}]\p{Ll}*(?:\s+[\p{Lu}\p{Ll}]\p{Ll}*)*$/

现在,第一个字符或每个单词可以是大写字母或小写字母。


智能推荐

soft / hard attention 机制 理解——机器学习中的soft 和 hard

Soft attention是一种全局的attention,其中权重被softly地放在源图像所有区域 Hard attention一次关注图像的一个区域,采用0-1编码,时间花费较少,但是不可微分,所以需要更复杂的技术来进行训练   下图是从果壳网(quora)摘取的一篇回答 即在机器学习中soft 常常表示可微分,比如sigmoid和softmax机制 而hard常常表示不可微分 &...

浅谈C++的regex库

写在前面: 第四届CCCC团体程序设计天梯赛结束之后,知乎热榜出现了这个问题“如何评价第四届CCCC团体程序设计天梯赛”,这里面有些回答真的看得我笑出声,比如这个简简单单的回答:“第四届CCCC字符串大赛”。 L1部分的的确确地考察了大量的字符串操作(小声哔哔:考这么多字符串就算了 关键是还不给我用Python),但是并不能说这次天梯赛的题偏向了Ja...

Regex Expression的资料和笔记整理

维基百科:http://en.wikipedia.org/wiki/Regular_expression 正则表达式在线测试:http://tool.chinaz.com/regex/ 正则表达式,常用于文件搜索和数据校验等 iOS 提供了对正则表达式的支持:NSRegularExpression 常用的第三方正则库regexkit有全面的介绍(英文): http://regexkit.sourc...

YY的GCD [hard] [莫比乌斯反演]

传送门 题解传送门         ...

P,NP, NPC, NP-Hard问题的关系详解

我想试着把p, np, npc, np-hard问题给大家讲清楚。 在介绍之前,先说一下什么是确定性问题,什么是非确定性问题。 确定性: 比如小学学的加减乘除之类的,你只要按部就班的算,这个算法就能得到结果。 非确定性: 比如找大质数的问题。有没有一个公式,你一套公式,就可以一步步推算出来,下一个质数应该是多少,这样的公式是没有的。但可以告诉你一个答案,如果可以在多项式的时间内验证这个答案对不对,...

猜你喜欢

$ git reset --hard HEAD~1 出现的异常

2019独角兽企业重金招聘Python工程师标准>>> $ git reset --hard HEAD~1 Unlink of file 'Hello.java' failed. Should I try again? (y/n) This could mean that another program is using the file, which is preventing...

【转】NP-Hard和NP-Complete的区别

原文来自:http://hi.baidu.com/nuclearspace/item/e0f8a1b777914974254b09f4   对 NP-Hard问题和NP-Complete问题的一个直观的理解就是指那些很难(很可能是不可能)找到多项式时间算法的问题。因此一般初学算法的人都会问这样一个问题:NP-Hard和NP-Complete有什么不同?简单的回答是根据定义,如果所有NP问...

恢复git reset --hard之前的commit号

1. 依据:只要是在git库中提交过的commit,在.git/logs/refs/heads/分支名 文件中都有记录。所以只要拿到commit号,即使通过git reset --hard回滚到之前的commit号,也能够恢复回来。 2. 过程: 2.1 创建新分支:test_branch。 2.2 编辑文件,提交三次,用于测试。 此时,文件./git/logs/refs/heads/test_b...

git reset --hard 操作后的数据恢复

https://www.cnblogs.com/dongcanliang/p/11162235.html 在进行正文之前先简单介绍下git reset 命令 git reset git reset 命令用于改变当前的仓库状态,简单的场景用例:假设一次修改了两个文件,然而需要对这两个文件分别进行两次提交,在进行缓存操作时(git add),不小心将两个文件都进行了缓存,此时我们需...

The Design of Everyday Things 读书笔记

  近日抽闲读了老师推荐已久的这部设计史上的著作——唐纳德诺曼的The Design of Everyday Things,中文译名是《设计心理学》,全套共四部,我读了第一部,总的感觉就一个词——恍然大悟!被作者的细心以及擅于思考所折服,他能够抓住生活中很多人习以为常的不方便和小错误,从而解释糟糕的设计可能带给我们的麻烦甚至灾难。...

问答精选

Applying stats.percentileofscore to every row by column

df= I need a new column with the percentile score for each element with respect to the column. The final answer should look like this. I want the output of the stats.percentileofscore() function to be...

C - Creating node with multiple children by function - segmentation fault

I want to create tree with multiple children and create every node with a function. Here is my structure for node: And here is my function to create new node (with four children): When I run this func...

How to get all secrets in one call Azure key vault

I am using sample code explain here https://github.com/Azure-Samples/app-service-msi-keyvault-dotnet but they only explained how can we get single secrete not list of secrete. so to get all secrete I'...

increase eclipse IDE font size

I am using Eclipse I would like to increase the font size of the IDE, not just the font of the editor. Is there any way I can do that? I haven't been able to find a solution for this yet. you can try ...

Generating Guid by database automatically

It regards Entity Framework 6 but maybe it isn’t related to the version. I have some class which has Guid Id but by inheritance. Right now I would like to change this model to auto generate Id b...

相关问题

相关文章

热门文章

推荐文章

相关标签

推荐问答