11 lines
279 B
Markdown
11 lines
279 B
Markdown
A positive number with an optional decimal part is (per previous task): `pattern:\d+(\.\d+)?`.
|
|
|
|
Let's add the optional `pattern:-` in the beginning:
|
|
|
|
```js run
|
|
let regexp = /-?\d+(\.\d+)?/g;
|
|
|
|
let str = "-1.5 0 2 -123.4.";
|
|
|
|
alert( str.match(regexp) ); // -1.5, 0, 2, -123.4
|
|
```
|