2

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.

javac
  • 2,431
  • 4
  • 17
  • 26
Mostafa Fahimi
  • 510
  • 1
  • 8
  • 23
  • 1
    FYI: 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 Answers2

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