JavaScript: add or subtract from number in string
Posted
by yoavf
on Stack Overflow
See other posts from Stack Overflow
or by yoavf
Published on 2009-02-02T18:14:33Z
Indexed on
2010/05/01
13:07 UTC
Read the original article
Hit count: 153
JavaScript
|regex
I have a string that looks like "(3) New stuff" where 3 can be any number.
I would like to add or subtract to this number.
I figured out the following way:
var thenumber = string.match((/\d+/));
thenumber++;
string = string.replace(/\(\d+\)/ ,'('+ thenumber +')');
Is there a more elegant way to do it?
© Stack Overflow or respective owner