closes #3122
This commit is contained in:
parent
f0f43667a4
commit
962fa79b96
1 changed files with 14 additions and 0 deletions
|
@ -54,3 +54,17 @@ function parse(expr) {
|
|||
|
||||
alert( parse("-1.23 * 3.45") ); // -1.23, *, 3.45
|
||||
```
|
||||
|
||||
As an alternative to using the non-capturing `?:`, we could name the groups, like this:
|
||||
|
||||
```js run
|
||||
function parse(expr) {
|
||||
let regexp = /(?<a>-?\d+(?:\.\d+)?)\s*(?<operator>[-+*\/])\s*(?<b>-?\d+(?:\.\d+)?)/;
|
||||
|
||||
let result = expr.match(regexp);
|
||||
|
||||
return [result.groups.a, result.groups.operator, result.groups.b];
|
||||
}
|
||||
|
||||
alert( parse("-1.23 * 3.45") ); // -1.23, *, 3.45;
|
||||
```
|
Loading…
Add table
Add a link
Reference in a new issue