Learn Functional Programming by Building a Spreadsheet - Step 74

Regex is not recognized.

Here are the instructions:

Step 74

In your highPrecedence function, declare a regex variable. Assign it a regular expression that matches a number (including decimal numbers) followed by a * or / operator followed by another number.

Each number, and the operator, should be in separate capture groups.

Here is my code:

const highPrecedence = str => {
  const regex = /([\d.]+)(\*|\/)([\d.]+)/;
}

The first group (and therefore the third one) works perfectly.
The problem is with the second (middle) group.
Instructions ask to capture the star (multiplication) operator or the division operator. These two characters are special so I escaped them.

I don’t understand why I get this error message:

Sorry, your code does not pass. Hang in there.

Your second capture group should match a * or / operator. Use a character class in the capture group.

I’ve tried many combinations:

(\*)|(\/)
([\*|\/])
([\*]|[\/])

None of them work

Hi,
I was several hours stuck with this :slight_smile:

You don’t have to use the or operator “|”.
But you have to escape the division operator “/”.
Try this in the second capture group

 ([*\/])

Thank you for your response

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.