Last Updated: February 25, 2016
·
285
· ilkelma

Regex matcher for formatted price

I needed this to extract the number behind an angular.js formatted price. The whole line that I found in my functional test using Protractor's find by binding was:

Price: $425.00

I needed to match that later in the test to be sure a model value was defaulted correctly to that value. Here's the matcher I came up with to eliminate the noise

var price = 'Price: $425.00'.replace(/^.*\$|\.(.*)/g, '');
console.assert(price, '425');

You can see it in action and play with it here too (I love this site):
http://www.regexr.com/39ftk