Java正则表达式匹配一句英文句子(大写字母开头,结尾有句号)
正则表达式:
[A-Za-z]+[A-Za-z0-9_,"#;.() \s]*[.]$或^([A-Z]){1}[^.]*.
测试代码:
import java.util.regex.Matcher;
import java.util.regex.Pattern;public class Contain_Test {public static void main(String[] args) {String example1="I am a handsome boy.";String example2="Where there is a will, there is a way.";String regex="[A-Za-z]+[A-Za-z0-9_,\"#;.() \\s]*[.]$";//匹配一句英文语句。String anotherRegex="^([A-Z]){1}[^.]*.";Pattern pattern=Pattern.compile(regex);Pattern anotherPattern=Pattern.compile(anotherRegex);Matcher matcher1=pattern.matcher(example1);Matcher matcher2=pattern.matcher(example2);Matcher matcher3=anotherPattern.matcher(example1);Matcher matcher4=anotherPattern.matcher(example2);boolean result1=matcher1.matches();boolean result2=matcher2.matches();boolean result3=matcher3.matches();boolean result4=matcher4.matches();System.out.println("regex's result:");System.out.println(example1+" =>"+result1);System.out.println(example2+" =>"+result2);System.out.println("anotherRegex's result:");System.out.println(example1+" =>"+result3);System.out.println(example2+" =>"+result4);}
}
测试结果:
regex's result:
I am a handsome boy. =>true
Where there is a will, there is a way. =>trueanotherRegex's result:
I am a handsome boy. =>true
Where there is a will, there is a way. =>true
Java正则表达式匹配一句英文句子(大写字母开头,结尾有句号)相关推荐
- 【转】正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度
[转]正则表达式 匹配中文,英文字母和数字及_的写法!同时控制长度 using System.Text.RegularExpressions; 匹配中文:[\u4e00-\u9fa5] 英文字母:[a ...
- Java 正则表达式匹配模式[贪婪型、勉强型、占有型]
转载自 Java 正则表达式匹配模式[贪婪型.勉强型.占有型] Greediness(贪婪型):最大匹配 X?.X*.X+.X{n,} 是最大匹配.例如你要用 "<.+>&qu ...
- js 实现 将一句英文的首字母转大写,其它转小写
//将一句英文的首字母转大写,其它转小写 var word='Welcome to my little WORLd. I have a DREAM thAt iS TO fLy to tLe sky' ...
- java正则验正斜杠_JAVA资格认:java正则表达式匹配斜杠
在正则表达式里面匹配一个斜杠,需要用4个斜杠: Java代码 import java.util.regex.Matcher; import java.util.regex.Pattern; publi ...
- java 正则表达式匹配数字_java正则表达式匹配所有数字的案例
用于匹配的正则表达式为 :([1-9]\d*\.?\d*)|(0\.\d*[1-9]) ( [1-9] :匹配1~9的数字: \d :匹配数字,包括0~9: * :紧跟在 \d 之后,表明可以匹配零个 ...
- java正则表达式匹配字符串_java正则表达式如何匹配字符串
java正则表达式匹配字符串的方法:使用tostring,代码为[while(matcher.find()){tmp.add(matcher.group(1).toString());}]. java ...
- puts遇到空格无法输出_输入一句英文,只包含字母和空格,如何输出这句英文中.....-黑马程序员技术交流社区...
//输入一句英文,只包含字母和空格,如何输出这句英文中的最长单词?再把每个单词的首字母转换成大写! #include #include int main(int argc, const char * ...
- el-input中,输入input和失去焦点blur时进行校验——正则表达式之只能输入数字和大写字母 只能输入数字 颜色值的正则表达式-3位和6位 标签的回车事件
el-input中,输入input和失去焦点blur时进行校验--正则表达式之只能输入数字和大写字母 & 只能输入数字 & 颜色值的正则表达式-3位和6位 & 标签的回车事件 ...
- 用windows“记事本”创建一个文本文件(hamlet.txt),其中每行包含一段英文。试读出文件的全部内容,并判断:(1)该文本文件有多少行?(2)文件中以大写字母开头的有多少行?
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 目录 题目: 代码: 效果截图: 总结 题目: 用windows"记事本"创建一个文本文件(hamlet.txt) ...
最新文章
- if(a==1且a==2且a==3),有没有可能为true?
- 小米台灯底座接口很松_呵护你的眼,米家台灯1S
- 牛客多校2 - Cover the Tree(dfs序)
- 适合新手入门的8个python项目_推荐:一个适合于Python新手的入门练手项目
- php.ini var dump,php安装xdebug后var_dump()不能输变量内容解决办法
- MyBatis的概述及使用
- C++数据库编程 ODBC连接SQL Server数据库
- SI4463低功耗测试-STC单片机一样可以超低功耗
- 移动端图片浏览器轮子
- 从零开始学习区块链技术
- 鹿晗关晓彤公开恋情,是如何把微博服务器搞炸的? 附大型网站高可用架构和解决方案...
- 全能修图工具:Pixelmator Pro for Mac
- 深入浅出内存马(一)
- 51单片机入门——Keil uVision4的使用
- 南京林业大学本科毕业论文答辩PPT模板
- 串口发送程序linux,单片机IO口模拟串口程序(发送+接收
- idea 推送代码报‘error: The following untracked working tree ……’
- Windows下使用SSD检测
- Excel表中查找、去除重复项方法合集
- win10 Edge关闭smartscreen筛选器