Altered String Alert

0

I have the following code:

var string = "Este aqui é o valor do cliente 000.000.00 01";
var str_subs = "129.000.000 02";
string = string.replace(/\d\d\d\.\d\d\d\.\d\d \d\d/g, str_subs);

alert("Valor Original: " & ??????); -> No caso aqui eu deveria mostrar 000.000.00 01
alert("Valor Novo: " & str_subs);

I need to show the ORIGINAL value that replace found before changing, how should I proceed?

    
asked by anonymous 23.05.2014 / 23:30

1 answer

3

You could be doing something like this:

 
var str = "Este aqui é o valor do cliente 000.000.00 01";
var old = str.match(/\d\d\d\.\d\d\d\.\d\d \d\d/);
var to_replace = "129.000.000 02";
var new_str = str.replace(/\d\d\d\.\d\d\d\.\d\d \d\d/g, to_replace);

alert("Valor Original: " + old);
alert("Valor Novo: " + to_replace);

Demo

    
23.05.2014 / 23:42