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
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 14685
    
  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: 16811
    
  19

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

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

Joined: Sep 28, 2004
Posts: 16811
    
  19

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

There are only numbers in the parenthesis, but it's interesting to know. Thank you.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Remove number in parenthesis using regular expression
 
Similar Threads
20060122 to 01/22/2006
Regex and split method question
Need help with regular expression
Reg Expression to Search for Non-matching Pattern
regular expression example telephone number validation