fpcbk

split也是用到了正则表达式

replace 是没有用正则表达式,全部替换

replaceAll 和replaceFirst是用了正则表达式

replaceAll替换所有,replaceFirst是替换第一个出现的

String s = "my.test.txt";
System.out.println(s.replace(".", "#"));
System.out.println(s.replaceAll(".", "#"));
System.out.println(s.replaceFirst(".", "#"));
运行结果:

my#test#txt
###########  若不想替换所有非.,转义下s.replaceAll("\\.""#"),替换数字:"\\d"、也可以单换一个数字。
#y.test.txt

.匹配除换行符以外的任意字符

^匹配字符串的开始

$匹配字符串的结束

*重复零次或更多次

+重复一次或更多次

?重复零次或一次

分类:

技术点:

相关文章:

  • 2022-02-27
  • 2021-10-03
  • 2021-10-03
  • 2021-11-26
  • 2021-12-24
  • 2022-02-09
猜你喜欢
  • 2021-10-03
  • 2021-10-03
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
相关资源
相似解决方案