| Author |
Remove number in parenthesis using regular expression
|
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14685
|
|
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
|
|
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
|
|
Silly me I was doing "\\(.*\\)"... Thanks Henry
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16811
|
|
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
|
|
|
There are only numbers in the parenthesis, but it's interesting to know. Thank you.
|
 |
 |
|
|
subject: Remove number in parenthesis using regular expression
|
|
|