RegExp - My solution works, but is rejected

Tell us what’s happening:
Describe your issue in detail here.

Location: JavaScript Algorithms and Data Structures → Regular Expressions → Specify Upper and Lower Number of Matches

My solution works (satisfy all existing requirements given), but program rejected my solution. In “Hint” I saw that program expect that regexp have to count specificaly on given string. My solution works for all strings (and for given, also), but (it seems) there is previously minded condition that is not written in list of requirements.

(this is not question; rather it is suggestion for author to correct test - there were some other similar situations, but I didn’t remind those)

Your code so far

let ohStr = "Ohhhhh no";
// my solution - works for all possible strings:
let ohRegex = /[^h]h{3,6}[^h]/; // Change this line
// Hint says: let ohRegex = /Oh{3,6}\sno/;
let result = ohRegex.test(ohStr);

Your browser information:

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

Challenge: Specify Upper and Lower Number of Matches

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Your solution fails to meet the requirements

Change the regex ohRegex to match the entire phrase Oh no only when it has 3 to 6 letter h’s.

OK, I understand and I will use them in future posts.

Yes, later I was (again) analyze whole problem and saw that it literaly require “given” string, not “any” string.
I am programmer for 30 years (other languages) and have habit of solving problems “in general”, not only for specific situations.
Thank you very much, and sorry.

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