Java 如何删除括号内的字符串?

Java 如何删除括号内的字符串?,java,regex,string,replace,Java,Regex,String,Replace,我有一个单词列表,我必须删除括号内的字符串列表 day[1.0,264.0] developers[1.0,264.0] does[1.0,264.0] employees[1.0,264.0] ex[1.0,264.0] experts[1.0,264.0] fil[1.0,264.0] from[1.0,264.0] gr[1.0,264.0] 我应该 day developers does . . . . 这种方法正确吗 String rep=day[1.0,264.0]; S

我有一个单词列表,我必须删除括号内的字符串列表

day[1.0,264.0]
developers[1.0,264.0]
does[1.0,264.0]
employees[1.0,264.0]
ex[1.0,264.0]
experts[1.0,264.0]
fil[1.0,264.0]
from[1.0,264.0]
gr[1.0,264.0]
我应该

day

developers

does
.
.
.
.
这种方法正确吗

String rep=day[1.0,264.0];  
String replaced=rep.replace("[","]","1.0","2");

这种方法正确吗

Pattern stopWords = Pattern.compile("\\b(?:i|[|]|1|2|3|...)\\b\\s*",Pattern.CASE_INSENSITIVE);    
Matcher matcher = stopWords.matcher("I would like to do a nice novel about nature AND people");    
String clean = matcher.replaceAll("");
使用


正则表达式:
\\[.*]
因为
[
是正则表达式世界中的一个特殊字符(meta-chacarter),你必须转义它,它将反斜杠视为文字。
*
用于b/w'[此处的任何内容]

只需将它们替换为零即可

rep.replaceAll("\\[.*\\]", "");

只需通过“[”标记字符串并获取第一部分

StringTokenizer st = new StringTokenizer(str, "[");
String part1 = st.nextToken();

这是一种比目前其他建议稍微简单的方法

String s = "day[1.0,264.0]";
String ofInterest2 = s.substring(0, s.indexOf("["));
我会给你输出的

day

这也允许括号后面的内容

     String rep="day[1.0,264.0]";
     int firstIndex = rep.indexOf('[');
     int secondIndex = rep.indexOf(']');
     String news = rep.substring(0, firstIndex) +    rep.substring(secondIndex+1,rep.length());

试着了解哪种变体有效。
     String rep="day[1.0,264.0]";
     int firstIndex = rep.indexOf('[');
     int secondIndex = rep.indexOf(']');
     String news = rep.substring(0, firstIndex) +    rep.substring(secondIndex+1,rep.length());