I would need a regular expression that treats numbers with dots and commas the same way. Commas should not be treated as thousand separators.
Example:
9.8
9,8
should return 9.8 both
I tried this, but it doesn't work.
^(\d+(?:[\.\,]\d{2})?|)$
I would need a regular expression that treats numbers with dots and commas the same way. Commas should not be treated as thousand separators.
Example:
9.8
9,8
should return 9.8 both
I tried this, but it doesn't work.
^(\d+(?:[\.\,]\d{2})?|)$
Your regex ^(\d+(?:[\.\,]\d{2})?|)$
matches numbers that have exactly 2 decimals, if you want to match any number (1 or more) of decimals, use:
^(?:\d+(?:[.,]\d+)?|)$
PHP
$re = '/(,)/mx';
$str = '9.8 \n9,8';
$subst = '.';
preg_replace($re, $subst, $str);
JAVASCRIPT
var re = /(,)/gmx;
var str = '9.8 \n9,8';
var subst = '.';
str.replace(re, subst);
PYTHON
import re
p = re.compile(r'(,)', re.MULTILINE | re.VERBOSE)
str = "9.8 \n9,8"
subst = "."
re.sub(p, subst, str)