正则表达式如何用空格替换其中的所有方括号和内容

时间:2022-07-20 21:43:07

I have a file name as AcbsIncorSigRemover[1.1].java

我有一个文件名为AcbsIncorSigRemover [1.1] .java

I want to rename this file as AcbsIncorSigRemover.java

我想将此文件重命名为AcbsIncorSigRemover.java

Can you provide me with valid regex validation?

你能为我提供有效的正则表达式验证吗?

I have thousands of files like this that need to be renamed. Please help.

我有成千上万的这样的文件需要重命名。请帮忙。

2 个解决方案

#1


2  

Try

"AcbsIncorSigRemover[1.1].java".replaceAll("\\[(.*?)\\]","")

output

AcbsIncorSigRemover.java

Demo

#2


-3  

 String s = "AcbsIncorSigRemover[1.1].java";    
 s= s.substring(0,s.indexOf("["))+".java";

#1


2  

Try

"AcbsIncorSigRemover[1.1].java".replaceAll("\\[(.*?)\\]","")

output

AcbsIncorSigRemover.java

Demo

#2


-3  

 String s = "AcbsIncorSigRemover[1.1].java";    
 s= s.substring(0,s.indexOf("["))+".java";