我试着转换这个:
$regex = "/^[0-9]+[0-9\.]*(?<!\.)$/"
所有这些,但没有一个是正确的:
var regex = /^(?!\.$)[0-9]+[0-9\.]*/;
var regex = /^(?!.*\.$)[0-9]+[0-9\.]*/;
var regex = /^[0-9]+[0-9\.]*(?!\.$)/;
PHP 正则表达式正确拒绝1.1aand 1.,但 javascript 正则表达式没有。
我试着转换这个:
$regex = "/^[0-9]+[0-9\.]*(?<!\.)$/"
所有这些,但没有一个是正确的:
var regex = /^(?!\.$)[0-9]+[0-9\.]*/;
var regex = /^(?!.*\.$)[0-9]+[0-9\.]*/;
var regex = /^[0-9]+[0-9\.]*(?!\.$)/;
PHP 正则表达式正确拒绝1.1aand 1.,但 javascript 正则表达式没有。
Your PHP Regex may be better written as the following, which matches the same language, but is easier to read and doesn't need to use a negative look-behind:
$regex = "/^\d+(\.\d+)*$/"
It is also easy to translate it directly to a Javascript regex:
var regex = /^\d+(\.\d+)*$/;