-4

test()オブジェクト メソッドを使用して、最初に 1 つの +/- と、文字列内の 1 つの小数点を検証できる正規表現を作成しようとしています。現在、私の正規表現は : /[\d\b\t\+\-]|\./で、+、-、およびドット ( . ) を複数回使用できます。

+23.24または+0.23または-23.24または-0.23のような文字列を認識する正規表現が必要 です。

返信してください。

4

1 に答える 1

1

基本的な正規表現

/^[+-]\d+\.\d+$/

説明:

^     Match start of string
[+-]  Match either plus or minus
\d+   Match one or more numbers of digits
\.    Match a period, the \ escapes it since it means any character
\d+   Match one or more numbers of digits 
$     Match end of string
于 2013-05-24T12:39:04.033 に答える