当前位置:网站首页>正则表达式replaceFirst()方法具有什么功能呢?
正则表达式replaceFirst()方法具有什么功能呢?
2022-08-05 09:16:00 【qq_25073223】
转自:
下文笔者讲述replaceFirst()方法的功能简介说明,如下所示:
replaceFirst()方法的功能: 使用正则替换匹配出的第一个匹配出的字符串 replaceFirst()方法的语法: Pattern pattern = Pattern.compile("正则"); //生成正则表达式 Matcher matcher = pattern.matcher("正则122正则88988"); //匹配字符 matcher.replaceFirst("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 pattern = Pattern.compile("正则"); //生成正则表达式
Matcher matcher = pattern.matcher("正则122正则88988"); //匹配字符
System.out.println(matcher.replaceFirst("Java")); // 替换字符
}
}
------运行以上代码,将输出以下信息-----
Java122正则88988边栏推荐
猜你喜欢

Creo 9.0 基准特征:基准轴

百行代码发射红心,程序员何愁命不中女朋友!

js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)

Weekly Report 2022-8-4

ECCV 2022 Oral Video Instance Segmentation New SOTA: SeqFormer & IDOL and CVPR 2022 Video Instance Segmentation Competition Champion Scheme...

seata源码解析:TM RM 客户端的初始化过程

CCVR eases heterogeneous federated learning based on classifier calibration

工程制图知识点

欧盟 | 地平线 2020 ENSEMBLE:D2.13 SOTIF Safety Concept(上)

只有一台交换机,如何实现主从自动切换之nqa
随机推荐
Weekly Report 2022-8-4
Voice conversion相关语音数据集综合汇总
阿里云存储的数据库是怎么自动加快加载速度的呢www.cxsdkt.cn怎么设置案例?
嵌入式实操----基于RT1170 移植memtester做SDRAM测试(二十五)
工程制图知识点
Excuse me if you want to write data in mysql, with flink - connector - JDBC directly is ok, but I'm in the f
MQTT X Newsletter 2022-07 | 自动更新、MQTT X CLI 支持 MQTT 5.0、新增 conn 命令…
egg framework
js graphics operation one (compatible with pc, mobile terminal to achieve draggable attribute drag and drop effect)
歌词整理
无题七
tensorflow.keras无法引入layers
Dynamic memory development (C language)
汇编语言(8)x86内联汇编
Happens-before rules for threads
shell脚本实例
无题八
CPU的亲缘性affinity
周报2022-8-4
thinkPHP5 realizes clicks (data increment/decrement)