GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing javascript.info — Parse an expression back to the lesson Parse an expressionAn arithmetical expression consists of 2 numbers and an operator between them, for instance:
The operator is one of: There may be extra spaces at the beginning, at the end or between the parts. Create a function
For example:
A regexp for a number is: An operator is The slash We need a number, an operator, and then another number. And optional spaces between them. The full regular expression: It has 3 parts, with
To make each of these parts a separate element of the result array, let’s enclose them in parentheses: In action: The result includes:
We only want the numbers and the operator, without the full match or the decimal parts, so let’s “clean” the result a bit. The full match (the arrays first item) can be removed by shifting the array Groups that contain decimal parts (number 2 and 4) The final solution: As an alternative to using the non-capturing |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |