Regex is not my forte

I am going to admit that regex is not my strongpoint whatsoever. I have been playing around with some code this evening and trying to figure out what I am doing wrong, would anyone be able to lend a hand or tell me what I’m doing wrong…?

const string = "Hello"
const splitStr = string.split("")
	for (let i = 0; i < splitStr.length; i++) {
  	if (splitStr[i] === /^[A-Z]+$/g) console.log('we found an uppercase')
  }

I am trying to get it to recognise an uppercase letter and log it to the console.
I am hoping for it to return True, false, false, false, false however, nothing is being added to the console for the message for when it comes across the Capital H.

splitStr[i] === /^[A-Z]+$/g

For regular expressions, you don’t check against the pattern using an equality operator. You need to use a RegExp method.

Check out the documentation for regular expressions, pay special attention to the section " Using regular expressions in JavaScript":

1 Like

Hey @Ethan1021!

Right there with you :laughing:

But the documentation will help and there is also a helpful site called regex101. It is like a debugger for regular expressions. You can test your code and get detailed explanations. I used it a lot of the telephone validator project.

1 Like