Unexpected results: Regular Expressions - Specify Upper and Lower Number of Matches

Tell us what’s happening:
I’m trying to wrap my head around regex by experimenting in the challenges with alternative ways to solve them, often without much success. So, I compared the results from freeCode Camp against the results I get on the website regex101 (set to JavaScript) - with different outcomes.

The code below matches all test strings as I would expect on regex101 but fails on freeCodeCamp. I would like know why. Does anyone know why? ~Thanks!

Your code so far

let ohStr = "Ohhh no";
let ohRegex = /\b(?:oh{3,6})\b/ig; // Change this line
let result = ohRegex.test(ohStr);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:104.0) Gecko/20100101 Firefox/104.0

Challenge: Regular Expressions - Specify Upper and Lower Number of Matches

Link to the challenge:

Your regex doesn’t match “Ohhhh no”, it matches only “Ohhhh”

Thanks for answering.
Yes, it only matches “Ohhhh”, but shouldn’t it return true if that’s what I’m testing for and that pattern exists in the string?
(Sorry, I feel like I’m becoming more confused and not less confused as I go along with regex).

Sorry, scrap that. Brain fart. It does return true when I console log it - but obviously free Code Camp is performing different tests in the background. I feel a little silly …

Yeah, it’s using match to test. You can fix that by adding a few more characters to your regex

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