如何用JavaScript正则提取ParseHub爬取的货币数字(去除$及千分位点)
Got it, let's fix that regex issue for your ParseHub scraping task!
First, let's break down why your current regex ([-0-9/|,]+) isn't working for $1.000,00: it only matches continuous characters from the set [-0-9/|,]—the thousand-separator dot . isn't included here, so the match stops as soon as it hits that dot, leaving you with just 1.
Here are two straightforward solutions tailored to your needs:
Solution 1: Capture first, then clean up the dots
Use this regex to capture everything after the dollar sign (including dots and commas):
^\$([\d.,]+)$
^\$targets the leading dollar sign (we don't want to capture this part)([\d.,]+)captures the core value: all digits, thousand-separator dots, and the decimal comma
Then, in ParseHub, take the captured group (e.g., 1.000,00) and run a string replacement to remove all dots:
- Replace
.with an empty string - This turns
1.000,00→1000,00,800,64stays800,64, and100,00stays100,00
If you need to handle negative values like -$1.000,00, adjust the regex to:
^-?\$([\d.,]+)$
Solution 2: One-step regex replacement (if ParseHub supports it)
If ParseHub lets you use a regex to replace parts of the string directly, use this find-and-replace pair:
- Find regex:
^\$|\. - Replace with: Empty string
This will strip out both the leading dollar sign and all thousand-separator dots in one go, giving you exactly the format you need right away.
Both methods work for values with multiple thousand-separators too—like $1.234.567,89 will become 1234567,89 perfectly.
内容的提问来源于stack exchange,提问作者PmF111

