aspose 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 Java 8 in Action this week in the Java 8 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: 14687
    
  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: 18133
    
  39

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: 14687
    
  16

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

Joined: Sep 28, 2004
Posts: 18133
    
  39

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: 14687
    
  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
 
Similar Threads
Regex and split method question
Reg Expression to Search for Non-matching Pattern
Need help with regular expression
20060122 to 01/22/2006
regular expression example telephone number validation