This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 18545
    
  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: 14687
    
  16

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

Joined: Sep 28, 2004
Posts: 18545
    
  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: 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
regular expression example telephone number validation
Regex and split method question
Reg Expression to Search for Non-matching Pattern
20060122 to 01/22/2006
Need help with regular expression