Currency Amount Regex

Matches currency amounts with optional symbol and decimal.

パターン

/[$€£¥]\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?/g
→ ビジュアライザーで開く

テスト例

Price: $1,234.56, Tax: €89.99, Total: £2,000, JPY: ¥5000

コード例

javascript

const regex = /[$€£¥]\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?/g;
const result = str.match(regex);

python

import re
pattern = re.compile(r'[$€£¥]\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?')
result = pattern.findall(text)

go

import "regexp"
re := regexp.MustCompile(`[$€£¥]\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?`)
result := re.FindAllString(text, -1)
currencyfinancevalidation