如何编写正则表达式以传递以下内容?
LastName
LastName SecondLastName
LastName-SecondLastName
LastName, F
LastName SecondLastName, F
LastName-SecondLastName, F
LastName, FirstName
LastName SecondLastName, FirstName
LastName-SecondLastName, FirstName
LastName SecondLastName, FirstName SecondFirstName
LastName SecondLastName, FirstName-SecondFirstName
LastName-SecondLastName, FirstName-SecondFirstName
同时,至少以下内容应该失败:
Any special Character (,?!#@%* etc) at the begining
,FirstName
, FirstName
LastName,
LastName,Any special Character (,?!#@%* etc)
LastName,FirstName
基本上,在逗号之后,应该有一个空格和字母字符
资源:
[A-Za-z]+,\s+[A-Za-z]+
提前致谢! :)
答案 0 :(得分:1)
你怎么样尝试:
^[a-zA-Z]+([- ][a-zA-Z]+)?(, [a-zA-Z]+([- ][a-zA-Z]+)?)?$