We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f0f4366 commit 962fa79Copy full SHA for 962fa79
9-regular-expressions/11-regexp-groups/04-parse-expression/solution.md
@@ -54,3 +54,17 @@ function parse(expr) {
54
55
alert( parse("-1.23 * 3.45") ); // -1.23, *, 3.45
56
```
57
+
58
+As an alternative to using the non-capturing `?:`, we could name the groups, like this:
59
60
+```js run
61
+function parse(expr) {
62
+ let regexp = /(?<a>-?\d+(?:\.\d+)?)\s*(?<operator>[-+*\/])\s*(?<b>-?\d+(?:\.\d+)?)/;
63
64
+ let result = expr.match(regexp);
65
66
+ return [result.groups.a, result.groups.operator, result.groups.b];
67
+}
68
69
+alert( parse("-1.23 * 3.45") ); // -1.23, *, 3.45;
70
+```
0 commit comments