当前位置:网站首页>正则表达式replaceAll()方法具有什么功能呢?
正则表达式replaceAll()方法具有什么功能呢?
2022-08-05 09:16:00 【qq_25073223】
转自:
下文笔者讲述replaceAll()方法的功能简介说明,如下所示:
replaceAll()方法的功能: 使用正则替换匹配出的所有字符串 replaceAll()方法的语法: Pattern pattern = Pattern.compile("正则"); //生成正则表达式 Matcher matcher = pattern.matcher("正则122正则88988"); //匹配字符 matcher.replaceAll("Java")); //替换字符
例:
package com.java265.other; import java.util.regex.Matcher; import java.util.regex.Pattern; public class testClass { /* * java265.com Pattern类的使用 */ public static void main(String[] args) { Pattern p = Pattern.compile("([a-z]+)"); Matcher m1 = p.matcher("java265.com888888"); Matcher m2 = p.matcher("java67"); System.out.println(m1.replaceAll("牛牛")); System.out.println(m1.replaceAll("牛牛")); } } -----运行以上代码,将输出以下信息---- 牛牛265.牛牛888888 牛牛265.牛牛888888
边栏推荐
猜你喜欢
seata源码解析:事务状态及全局锁的存储
CVPR 2022 | 将X光图片用于垃圾分割,港中大(深圳)探索大规模智能垃圾分类
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
全面讲解GET 和 POST请求的本质区别是什么?原来我一直理解错了
如何实现按键的短按、长按检测?
Overall design and implementation of Kubernetes-based microservice project
XCODE12 在使用模拟器(SIMULATOR)时编译错误的解决方法
Why is pnpm hitting npm and yarn dimensionality reduction?
科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
How to realize the short press and long press detection of the button?
随机推荐
Creo 9.0 基准特征:基准平面
DPU — 功能特性 — 网络系统的硬件卸载
今天是元宵节~~
Example of Noise Calculation for Amplifier OPA855
百行代码发射红心,程序员何愁命不中女朋友!
tensorflow.keras cannot introduce layers
Rotation of the displayed value on the button
The Seven Weapons of Programmers
Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
科普大佬说 | 港大黄凯斌老师带你解锁黑客帝国与6G的关系
程序员的七种武器
HStreamDB Newsletter 2022-07|分区模型优化、数据集成框架进一步完善
Two-table query average grouping in sql server
动态库之间回调函数使用
汇编语言(8)x86内联汇编
Creo 9.0 基准特征:基准坐标系
并发之CAS
Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
深度学习21天——卷积神经网络(CNN):服装图像分类(第3天)
Comprehensively explain what is the essential difference between GET and POST requests?Turns out I always misunderstood