-3

I have textfile with lines like:

stackoverflow (200) stack over flow
stack over flow (150) over flow 
stack (15) 
stackoverflow (50) something

and I need to delete everything after () to get

stackoverflow (200)
stack over flow (150)
stack (15)
stackoverflow (50)

I tried with

 String string = new String(Files.readAllBytes(Paths.get("file.txt")));

  String result = string.split("\\)")[0];

but it doesn't work

Skillzone
  • 1
  • 3

1 Answers1

0

The following regex will do the trick. You replace all string of the form (200) to be removed \n with (200) (that is $1)

s.replaceAll("(\\(.*\\)).*\\n?", "$1\n")

Aimee Borda
  • 822
  • 2
  • 11
  • 22