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

时间:2022-12-28 20:22:45

I have a database with 50000 rows. I want to get all rows one by one, put them into a String variable and delete all characters between "(" and ")", then update the row. I just don't know how to delete all characters between "(" and ")". I want to do this with java.

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

2 个解决方案

#1


Your regular expression would be something like:

你的正则表达式将是这样的:

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

OR

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

The string consists of 3 parts:

该字符串由3部分组成:

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

I hope this helps

我希望这有帮助

#2


Use the replaceall(string regex, string replacement) statement, like this:

使用replaceall(字符串regex,字符串替换)语句,如下所示:

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

#1


Your regular expression would be something like:

你的正则表达式将是这样的:

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

OR

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

The string consists of 3 parts:

该字符串由3部分组成:

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

I hope this helps

我希望这有帮助

#2


Use the replaceall(string regex, string replacement) statement, like this:

使用replaceall(字符串regex,字符串替换)语句,如下所示:

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