首页 > 分享 > 正则表达式(Pattern与Matcher)

正则表达式(Pattern与Matcher)

最新推荐文章于 2023-07-28 12:02:59 发布

Jinandawang 于 2019-06-04 15:15:44 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

实例

package 测试草稿;

import java.util.regex.Matcher;

import java.util.regex.Pattern;

public class draft{

public static void main(String[] args) {

String str = "0.032";

Pattern pattern = Pattern.compile("^[0-9]*$");

Matcher matcher = pattern.matcher(str);

if(matcher.find()) {

System.out.println("整形");

}else if(Pattern.compile("^[0-9]*.[0-9]*$").matcher(str).find()){

System.out.println("浮点型");

}else {

System.out.println("字符型");

}

}

}

tips:

1、^表示开头,$表示结尾; 用 - 表示负号、短横、之类的都行(或者是  0-9  零至九 或者  a-z  a至z  的用法);

2、对于如何理解转义字符    :     正则表达式 会先要编译一次,变成正则标准模式(具有指定标志的模式),然后再与指定的字符串进行比较。可以看成编译两次。

常见正则符

相关知识

正则表达式(regex)实现模式匹配
手机号码的正则表达式是什么?
正则表达式中?=和?:和?!的理解
AI花卉艺术和图案画笔 Illustrator Floral Art & Pattern Brushes
HTML网页设计:十一、表单
计算机学院程科教授团队在模式识别与人工智能领域国际顶级期刊《Pattern Recognition》发表论文
浪漫花朵无缝花卉图案 Romantic Floral Seamless Pattern – 设计小咖
逆向分析基础
The distribution pattern and determinant factors of the main invasive alien plants in national nature reserves in China
Interspecific pattern and competitive relationship of plant community in Yancheng coastal wetland

网址: 正则表达式(Pattern与Matcher) https://m.huajiangbk.com/newsview676103.html

所属分类:花卉
上一篇: 《樱樱花语》粉色浪漫樱花主题婚礼
下一篇: 什么花有助于睡眠适合放在卧室