$1 代表 regex 里面第一个捕获性分组(这里是 ([^\\.]+) )捕获到的内容,例如:
"http://www.example.com/admin/test.kindeditor".replaceAll(regex, "$1") // => "test"在这里,$1 为 "test"
因为你的类文件里面有内部类比如说你的类文件叫做 test.class
然后这个文件里是
public class test{
test(){
}
public class 1{}
}
因为每个类必须对应一个文件而Class 1是内部类,所以就会出现test$1.class这个文件
import java.util.Scannerpublic class Test5 {
public static String getInputString(int type) {
Scanner scan = new Scanner(System.in)
switch (type) {
case 1:System.out.print("输入字串:")break
case 2:System.out.print("要查找字串为:")break
case 3:System.out.print("要替换的字串为:")break
}
String s=scan.nextLine()
return s
}
public static void main(String[] args) {
String str=getInputString(1)
String target=getInputString(2)
String replace=getInputString(3)
int i=0
while (str.indexOf(target)!=-1) {
i+=1
str=str.replaceFirst(target, replace)
}
System.out.println("共替换"+i+"次")
System.out.println("替换后结果如下:")
System.out.println(str)
}
}