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.
Asked
Active
Viewed 4,348 times
2
-
1FYI: Doing this in Java is likely to be MUCH slower than handling this with pure SQL. – Necreaux May 13 '15 at 12:11
-
When you see the light(TM), see this: http://stackoverflow.com/questions/4271186/how-can-i-use-mysql-replace-to-replace-strings-in-multiple-records – Ian2thedv May 13 '15 at 12:19
2 Answers
9
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:
\\( //This part matches the opening bracket
.*? //This part matches anything in between
\\) //This part matches the closing bracket
I hope this helps

Voidpaw
- 910
- 1
- 5
- 18
0
Use the replaceall(string regex, string replacement)
statement, like this:
data.replaceall(" and ", "");

bugs2919
- 371
- 1
- 8
-
-
String temp = "Bold (medium) ..."; I need to Remove (medium) and make my string like this "Bold ..." – Mostafa Fahimi May 12 '15 at 18:17
-
-
I told i have 50000 string which are diffrent and i need to delete every character in this strings between "(" and ")". All i need is a code that remove all characters between 2 special character. – Mostafa Fahimi May 12 '15 at 20:19
-
-
Sorry, i haven´t seen that it's says BETWEEN with that regular expression (regx) should work! – bugs2919 May 12 '15 at 20:23
-
it didn't work again. I use your regx but gave me an error: Invalid escape sequence (valid ones are \b \t \n \f \r \" \' \\ ) I really need this :( – Mostafa Fahimi May 12 '15 at 20:39
-
1@Matarata You need to escape the backslashes in java code before regex evaluation: s.replaceAll("\\\(.*?\\\)", "()"); – javac May 13 '15 at 11:21