• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Remove number in parenthesis using regular expression

 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to turn
7/1(10)+7/2(10)
into
7/1+7/2

Is there any regular expression to do that ?
 
Henry Wong
author
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:I'd like to turn
7/1(10)+7/2(10)
into
7/1+7/2

Is there any regular expression to do that ?


How about something like...

String newval = oldval.replaceAll("\\(\\d*\\)", "");

Henry
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Silly me I was doing "\\(.*\\)"... Thanks Henry
 
Henry Wong
author
Marshal
Pie
Posts: 21185
80
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:Silly me I was doing "\\(.*\\)"... Thanks Henry


BTW, if you don't care what's in the parens, then you should use "\\(.*?\\)" instead -- using a relunctant qualifier will only grab to the next close.

Henry
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are only numbers in the parenthesis, but it's interesting to know. Thank you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic