Java 行的正则表达式以大写字母开头

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18106596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 22:26:29  来源:igfitidea点击:

Regular expression for lines starts with capital letter word

javaregex

提问by user2609542

I have below lines of text in my text file,

我的文本文件中有以下几行文本,

James is working in London
this is a program developed in java
Program is working

I want to get the lines which have starting word with capital letter

我想获取以大写字母开头的行

James is working in London
Program is working

Thanks

谢谢

回答by vrdhn

For English language, you can use this

对于英语,你可以使用这个

^[A-Z].*

The ^ is for start of line. and [A-Z] means any capital letter.

^ 用于行首。[AZ] 表示任意大写字母。

回答by Paul Vargas

More faster if you use:

如果您使用,速度会更快:

if (Character.isUpperCase(line.charAt(0)) {
    System.out.println(line);
}