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
Written by A.M. Knight
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Regex
Authors
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#