Skip to content
Advertisement

How to use regular expression to find all numbers starting with “$”

I’m dealing with strings that contain non-comma-separated dollar values. For example:

“LOT 2 – $650000”

I need to be able to find the “$650000” and replace it with “$650,000”.

The problem is, I’m a complete novice when it comes to regular expressions. I found a post that suggested this for finding numbers:

JavaScript

This does successfully find both the “2” and the “650000” in my string. However, I want to make sure I only get numbers that start with “$”, so I only want to get the “$650000”.

Can anyone help me adapt the regular expression to get only numbers that start with “$”?

Advertisement

Answer

Kevin’s answer is better. I went the long way around:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement