<p>I am trying to match floating-point decimal numbers with a regular expression.  There may or may not be a number before the decimal, and the decimal may or may not be present, and if it is present it may or may not have digits after it.  (For this application, a leading +/- or a trailing "E123" is not allowed).  I have written this regex:</p>

<pre><code>/^([\d]*)(\.([\d]*))?$/
</code></pre>

<p>Which correctly matches the following:</p>

<pre><code>1
1.
1.23
.23
</code></pre>

<p>However, this also matches empty string or a string of just a decimal point, which I do not want.</p>

<p>Currently I am checking after running the regex that $1 or $3 has length greater than 0.  If not, it is not valid.  Is there a way I can do this directly in the regex?</p>

I think this will do what you want.  It either starts with a digit, in which case the decimal point and digits after it are optional, or it starts with a decimal point, in which case at least one digit is mandatory after it.
```
```
/^\d+(\.\d*)?|\.\d+$/
```
```