File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Remove number in parenthesis using regular expression Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Remove number in parenthesis using regular expression" Watch "Remove number in parenthesis using regular expression" New topic
Author

Remove number in parenthesis using regular expression

Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

I'd like to turn
7/1(10)+7/2(10)
into
7/1+7/2

Is there any regular expression to do that ?


[My Blog]
All roads lead to JavaRanch
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Silly me I was doing "\\(.*\\)"... Thanks Henry
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18914
    
  40

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

Joined: Nov 24, 2005
Posts: 14688
    
  16

There are only numbers in the parenthesis, but it's interesting to know. Thank you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Remove number in parenthesis using regular expression