私はphpでこの機能を持っています:
$html_price = "text text 12 eur or $ 22,01 text text";
preg_match_all('/(?<=|^)(?:[0-9]{1,3}(?:,| ?[0-9]{3})*(?:.[0-9]*)?|[0-9]{1,3}(?:\.?[0-9]{3})*(?:,[0-9] *)?)(?:\ |)(?:\$|usd|eur)+(?=|$)|(?:\$|usd|eur)(?:| )(?:[0-9]{1,3}(?:,| ?[0-9]{3})*(?:.[0-9]*)?|[0-9]{1,3}(?:\.?[0-9]{3})*(?:,[0-9] *)?)/', strtolower($html_price), $price_array1);
print_r($price_array1);
今、私はJavaScriptで同じ正規表現を使用したいのですが、エラーがあります:SyntaxError:無効な量指定子
私のJavaScript:
maxime_string = "((?<=|^)(?:[0-9]{1,3}(?:,| ?[0-9]{3})*(?:.[0-9]*)?|[0-9]{1,3}(?:\.?[0-9]{3})*(?:,[0-9] *)?)(?:\ |)(?:\$|usd|eur|euro|euros|firm|obro|€|£|gbp|dollar|aud|cdn|sgd|€)+(?=|$)|(?:\$|usd|eur|euro|euros|firm|obro|€|£|gbp|dollar|aud|cdn|sgd|€)(?:| )(?:[0-9]{1,3}(?:,| ?[0-9]{3})*(?:.[0-9]*)?|[0-9]{1,3}(?:\.?[0-9]{3})*(?:,[0-9] *)?))";
maxime_regex = new RegExp(maxime_string);
var text = "text text 12 eur or $ 22,01 text text";
var result = text.match(maxime_regex);
var max = result.length;
alert(result.length);
for (i = 0; i < max; i++)
{
document.write(result[i] + "<br/>");
}
手伝って頂けますか ?