RegEx - Match Beginning String [2021]

Tell us what’s happening:

I am failing to meet the following two requirements below; even though when I proceeded to the next challenge which focuses on matching the end of the string ie $ I managed to pass that challenge so I would assume that if I can match for the end of the string without fail I shouldn’t struggle with matching the beginning but alas…

I - Your regex should match "Cal" at the beginning of the string.
I understand that the caret ‘ˆ’ when not used within a character set directs the expression to focus only on the beginning of the string and yet when I run my code as is I still get an unfulfilled requirement: " Your regex should match "Cal" at the beginning of the string" which I am failing to understand why; whereas, when I alternatively put in “[ˆCal]” in my regex I fulfill this requirement which is counterintuitive to me :face_with_raised_eyebrow: shouldn’t the complete opposite work here instead? i.e. when the caret is used on a string outside of a character set /ˆCal/?

II - Your regex should search for "Cal" with a capital letter.

This one just defeats me. :expressionless: How else am I supposed to indicate that the “Cal” is capital other than how I have already used it in my code?

Your code so far

let rickyAndCal = "Cal and Ricky both like racing.";
let calRegex = /ˆCal/; // Change this line
let result = calRegex.test(rickyAndCal);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.146 Safari/537.36.

Challenge: Match Beginning String Patterns

Link to the challenge:

You’re absolutely right, /^Cal/ should work and it does, you’re just using the wrong ^ character. See the difference /ˆCal/ vs /^Cal/?

Thank you so much. Got it now :pray:

1 Like

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