Alex Rivera | Logout

Replace number in a string using regex or something else

Asked 2010-04-20T18:42:22.360
9

I am not so good with regex. I am struggling to find a solution for a small functionality.

I have a ajax response which returns a string like "Your ticket has been successfully logged. Please follow the link to view details 123432."

All I have to do is replace that number 123432 with <a href="blablabla.com?ticket=123432"> using javascript.

Edit
Report

1 Answer

1
var str = "Your ticket has been successfully logged. Please follow the link to view details 123432.";
str = str.replace(/\s+(\d+)\.$/g, '<a href="blablabla.com?ticket=$1">$&</a>');

this code will output

<a href="blablabla.com?ticket=123432">Your ticket has been successfully logged. Please follow the link to view details 123432.</a>
answered 2010-04-20T18:49:26.273

Your Answer