How do you only keep numbers and commas and dots (that occur between numbers) with regex?

Say you have the following string:

var string = "This shirt, is very nice. It costs DKK 1.500,00";

I want a function that will return 1.500,00.

The point is, that I only want to allow commas and dots that occur between numbers so I don’t end up with: ,.1.500,00

How would you do this using regexp in javascript?

Answer

How about this – bd[.,d]*b ?

Leave a Reply

Your email address will not be published. Required fields are marked *