删除字符串中2个字符之间的所有字符

Remove all characters between 2 characters in a String

我有一个包含 50000 行的数据库。我想一一获取所有行,将它们放入一个字符串变量中并删除“(”和“)”之间的所有字符,然后更新该行。我只是不知道如何删除“(”和“)”之间的所有字符。我想用 java.

来做到这一点

使用replaceall(string regex, string replacement)语句,像这样:

data.replaceall(" and ", "");

您的正则表达式类似于:

data.replaceAll("\(.*?\)", "()"); //if you want to keep the brackets

data.replaceAll("\(.*?\)", ""); //if you don't want to keep the brackets

字符串由三部分组成:

\(  //This part matches the opening bracket
.*?  //This part matches anything in between
\)  //This part matches the closing bracket

希望对您有所帮助