Hi, people!
I need to find all numbers and multiply them by ten in
document.getElementById('numbers').innerHTML
I know that it can be done by php with
Code PHP:$text = preg_replace("|\d+|e", "\\0*10", $text)
But how it can be done by javascript?
| SitePoint Sponsor |
Hi, people!
I need to find all numbers and multiply them by ten in
document.getElementById('numbers').innerHTML
I know that it can be done by php with
Code PHP:$text = preg_replace("|\d+|e", "\\0*10", $text)
But how it can be done by javascript?



This might be useful:http://www.javascriptkit.com/jsref/regexp.shtml
http://pritisolanki.blogspot.com/ - Learning Excellence
http://pritisolanki.wordpress.com/ -Sharing Opportunities
Yes, thanks, it is quite useful.
But i just know how to replace with fixed string
str.replace(/\d+/g, "12345")
But is it possible in JavaScript to replace it with function? Something like
str.replace(/\d+/g, \0*10) ?
that is very close!
But what is wrong with
Here, $1 just cannot be converted to number. It prints NaN.Code JavaScript:str = "123"; document.write (str.replace(/(\d+)/, "$1"*1))
Though if it is "$1"+1, it prints 1231 (as normal string).
Is it possible to convert $1 to number?
Bookmarks