在正则表达式的世界中可能吗?

问题描述 投票:0回答:1

这是我所做的

 [a-zA-Z][a-zA-z(\. | \s)]+[a-zA-Z]$

但是我到底想要什么。

表达接受:

开始时

1- Start with non-space character(A-za-z)

Middle

2- Spaces between words are allowed(\s)
3- dot(.) is allowed between chars only once, and occurs only, after any non-space character(A-za-z)
4- Same as 3, but dot is replaced by dash(-)
5- And if dash found the expression accept only, non-space char(A-za-z) and first char should be in uppercase.

结尾为

6- Any non-space char(A-za-z)

示例:

a. M. john
b. M john
c. M-John
d. M. john-Rich

如果不是

Suggest how much it can possible
regex regex-lookarounds regex-group regex-greedy
1个回答
0
投票

尝试(?i)^(?!.*\..*\.)(?!.*-.*-)[a-z](?:[a-z ]|(?:(?<=[a-z])-(?=[a-z]))|(?:(?<=[a-z])\.))+$

© www.soinside.com 2019 - 2024. All rights reserved.