In comp.lang.javascript message <8P-dneqFHrL179bbnZ2dnUVZ_jadnZ2d@comcas
t.com>, Wed, 16 May 2007 17:07:51, -Lost <maventheextrawords@techie.com>
posted:
Quote:
>laredotornado@zipmail.com wrote:
Quote:
Quote:
> I have a span that contains text of the form
> var spanHtml = "My Tab Content (7)";
> The content is guaranteed to end with a string of the form "(#)"
>>where
>"#" is a whole number. My question is, how would I write a regular
>expression that would change the value of #, given another number?
>For example, given the above variable, if I had
> var newNumber = 15;
> I would want the variable spanHtml to contain
> "My Tab Content (15)".
Quote:
>I make no claims that this is the best possible solution. My Regular
>Expression knowledge is severely limited.
Then why respond?
Quote:
>One small change could be, since you know it is always (#):
Quote:
>Again though, I am sure a regexp guru will along momentarily to suggest
>an improvement.
Then why respond so soon?
spanHtml = spanHtml.replace(/\d/, 15) ;
If the input may contain multiple digits, change \d to \d+ .
If the input may be signed, precede /d by [+-]? .
It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.