Match Single Character with Multiple Possibilities - Not Working

Match Single Character with Multiple Possibilities - Not Working
0.0 0

#1

Tell us what’s happening:

let quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
let vowelRegex = /[aeiou]/gi; // Change this line
let result = vowelRegex.match(quoteSample); // Change this line

In searching for help on this one, I ran across the creator’s thread on FCC which has the solution. Even copying/pasting the solution didn’t work, which only differs from mine in the last line:
His last line: var result = vowelRegex.match(quoteSample).length.

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-single-character-with-multiple-possibilities


#2

I should add that all five tests have failed.

X You should find all 25 vowels.
X Your regex vowelRegex should use a character class.
X Your regex vowelRegex should use the global flag.
X Your regex vowelRegex should use the case insensitive flag.
X Your regex should not match any consonants.


#3

You should simply have a double look at the syntax: match is not a RegExp method, is a string one :wink:


#4

Thanks, I’m still confused how the creator’s solution is thus:


var quoteSample = "Beware of bugs in the above code; I have only proved it correct, not tried it.";
var myRegex = /[aeiou]/gi; // Change this line
var result = myRegex.match(quoteSample).length; // Change this line

Is he not calling .match() as a method of myRegex? The post is from 2016, so has JavaScript changed since then?


#5

Honestly I doubt (it is changed but not under regexp aspect as far as I know ). Furthermore he is using the length property where it should return an array so…I can’t say. Can I ask you where did you find it?


#6

Not sure if it’s coincidence or not, but this time when I searched Google for the same thing, the link to this forum didn’t show up…

I’m not trying to call anyone out, and I initially made the same mistake which is why I was confused when I found the same syntax in the solution given by the person who wrote the challenge.


#7

Well, that’s what I call a deep search :rofl:
I see a lot of test condition and other stuff, more related to the background than the challenge itself^^ Probably there something under the hood ( here you can see a match method used to customize the regex MDN - Regex @@Match ), or maybe was just a typo; anyway I think that guy is still here around so we can ask himself directly^^

@erictleung ^^


#8

I do try to Read and Search long before I Ask :grin:. I hit a wall with that one, but you pointed me in the right direction.


let ohStr = "Ohhh no";
let ohRegex = /h{3,6}/; // Change this line
let result = ohRegex.test(ohStr);

Actually, this problem is failing, too. It’s finding a match in “Ohhhhhhh no” (with 7 h) and I’m not sure why. It’s like the upper bound isn’t registering, because even if I use /h{3,3}/ it still matches everything after 3.


#9

Yep, that’s because even in this string: “hhhhhhh” you can find this string ( matched by your regex): “hhhhhh”
Just this morning someone had the same doubt, you can search for his topic here around ^^


#10

Dang it…of course. See? I skipped straight to Ask and put my foot in my mouth.


#11

Yeah i was a bit caught out with this one too. Almost feels like the solution you need to step back towards the first few RegEx exercises.

When you crack it you’ll feel silly for thinking about it so much! Or at least I did…


#12

Thanks for the bat signal! :wink:

@javineya take a look at the code examples in the challenge description and take a look at your code. I guess I designed them so that you can’t just copy paste things, you gotta read your code and realize what you’re doing. The error is in the last light with let result. Hope that helps! And good luck! :+1:

Edit: Nevermind, just read through the comments a bit. Mmm I guess I made a mistake when initially writing up the challenge and someone fixed it in production. I’m assuming that when people were QA-ing my challenge, they found that the assumption that an individual would think to use the .length method would be too confusing, so they left it as just the regex itself. That’s be my guess and I hope that helps!


#13

Ah, thank you for the reply :bat:

I think this clears up the doubts, let’s hear the OP!


#14

Hey, I appreciate the response, @erictleung.

It was my mistake because .test() is a RegEx method and we hadn’t been tasked with typing .match() yet. I just followed the syntax pattern from .test() and it wasn’t working, but @Layer pointed out my error.

Keep up the great work!