Finance
Euro amount Regex
Euro amounts are written differently across Europe. Some writers put the € sign first and use English separators, while many countries put the sign last and use a dot or space for thousands with a comma for cents. This pattern accepts both styles: a leading € with comma or dot grouping, or a trailing € with dot or space grouping and comma decimals. It is useful for parsing receipts, price lists and marketplace exports from several countries. Because the separators are ambiguous, it checks the shape only and cannot tell you whether 1.234 means one thousand or one point two.
Pattern (JavaScript)
/^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$/Starts at the start of the line/string, then (the character "€", then a space, optionally (zero or one time), then (a digit (0-9), between 1 and 3 times, then (one of the characters .,, then exactly 3 digits), zero or more times OR one or more digits), then (one of the characters .,, then exactly 2 digits), optionally (zero or one time) OR (a digit (0-9), between 1 and 3 times, then (one of the characters . , then exactly 3 digits), zero or more times OR one or more digits), then (the character ",", then exactly 2 digits), optionally (zero or one time), then a space, optionally (zero or one time), then the character "€"), then the end of the line/string.
Examples
Matches
- ✓ €1,234.56
- ✓ 1.234,56 €
- ✓ € 99
- ✓ 12,50€
Does not match
- ✗ EUR 12
- ✗ €12,5
- ✗ €
- ✗ $12.50
Try it
0 matches (JavaScript engine)
€1,234.56
1.234,56 €
€ 99
12,50€
EUR 12
€12,5
€
$12.50Code in 8 languages
Converted automatically from the JavaScript pattern; language-specific notes are shown where the syntax or support differs.
JavaScript
const re = /^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$/g;
const text = "€1,234.56";
const matches = [...text.matchAll(re)].map((m) => m[0]);
console.log(matches);Python
import re
pattern = re.compile(r'^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$')
text = '€1,234.56'
matches = [m.group(0) for m in pattern.finditer(text)]
print(matches)PHP
<?php
$pattern = '/^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$/';
$text = '€1,234.56';
preg_match_all($pattern, $text, $matches);
print_r($matches[0]);Java
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Pattern pattern = Pattern.compile("^(?:€ ?(?:\\d{1,3}(?:[.,]\\d{3})*|\\d+)(?:[.,]\\d{2})?|(?:\\d{1,3}(?:[. ]\\d{3})*|\\d+)(?:,\\d{2})? ?€)$");
String text = "€1,234.56";
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
System.out.println(matcher.group());
}
}
}Go
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$`)
text := "€1,234.56"
fmt.Println(re.FindAllString(text, -1))
}C#
using System;
using System.Text.RegularExpressions;
var pattern = new Regex(@"^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$");
var text = "€1,234.56";
foreach (Match m in pattern.Matches(text))
{
Console.WriteLine(m.Value);
}Rust
// Cargo.toml: regex = "1"
use regex::Regex;
fn main() {
let re = Regex::new(r"^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$").unwrap();
let text = "€1,234.56";
for m in re.find_iter(text) {
println!("{}", m.as_str());
}
}- Add regex = "1" under [dependencies] in Cargo.toml.
Ruby
pattern = /^(?:€ ?(?:\d{1,3}(?:[.,]\d{3})*|\d+)(?:[.,]\d{2})?|(?:\d{1,3}(?:[. ]\d{3})*|\d+)(?:,\d{2})? ?€)$/
text = '€1,234.56'
matches = text.to_enum(:scan, pattern).map { Regexp.last_match[0] }
p matchesFrequently asked questions
- Why does the pattern accept the € sign in two places?
- English-language sites usually write €10.00, while German, French and Spanish usage puts the sign after the number, as in 10,00 €. Supporting both avoids rejecting perfectly normal input.
- Does it match amounts written with the EUR code?
- No. This pattern requires the € symbol. If your data uses the three letter code, add an alternative for EUR or use the ISO currency code pattern alongside it.
- How do I convert a matched amount to a number?
- Decide which separator is the decimal one based on the format that matched, remove the grouping characters, then replace the decimal comma with a dot. Do this in code, because the regex alone cannot resolve the ambiguity.
Related patterns
- US dollar amount^-?\$(?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d{2})?$
- Common ISO 4217 currency code^(?:USD|EUR|GBP|JPY|CHF|CAD|AUD|NZD|CNY|HKD|SGD|INR|AED|SAR|SEK|NOK|DKK|ZAR|BRL|MXN)$
- Accounting negative amount in parentheses^\((?:\d{1,3}(?:,\d{3})*|\d+)(?:\.\d{2})?\)$
- American Express card number shape^3[47]\d{2}[ -]?\d{6}[ -]?\d{5}$