Regex matching first capital letter followed by on

2020-05-08 06:39发布

That is my regular expression:

[A-Ö]{1}[a-ö]

When I write that everything is fine until I write another small letter it doesn't work. E.g. Ab works, but Cmo or Klfdklgklhsh don't work. How can I do this?

EDIT BASED ON COMMENTS:

If I use [A-Ö]{1}[a-ö]+ then it also supports ab, klofn and nnn for example. I need for the first letter to be only a capital letter.

标签: java regex
2条回答
够拽才男人
2楼-- · 2020-05-08 06:58
[A-Ö]{1}[a-ö]*

The * means zero or more, if you require a lowercase letter to follow, then use

[A-Ö]{1}[a-ö]+
查看更多
放我归山
3楼-- · 2020-05-08 07:02

Note that [A-Ö] matches all lower and uppercase letters and a lot of other symbols, too.

enter image description here

You need

[A-ZÖ][a-zö]+

See regex demo

Note that + matches 1 or more occurrences of the preceding subpattern.

查看更多
登录 后发表回答