Last Updated: February 25, 2016
·
448
· 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

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside