Match Beginning String Patterns1

Tell us what’s happening:

Please can you help me I can do that:

Your regex should search for “Cal” with a capital letter.
Your code so far


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

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.99 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/regular-expressions/match-beginning-string-patterns

You’re looking for only the word ‘Cal’, and only when it is at the beginning of the string. Your regex looks for ‘and Ricky both like racing’.

And what Regex should look?

Here’s the example from the challenge:

let firstString = "Ricky is first and can be found.";
let firstRegex = /^Ricky/;
firstRegex.test(firstString);

^ means ‘beginning of the string’.

Klaudia this is the second thread you’ve posted, read carefully the replies to the previous one and try to understand what to do

If I put that ^ my code isn’t right.

/and Ricky both like racing/

This is wrong. Look at the example:

let firstString = "Ricky is first and can be found.";
let firstRegex = /^Ricky/;
firstRegex.test(firstString);

Can you help me mmore??

Not without giving you the answer.

No seriously no the answer

Answer these questions:

  1. Which word are you looking for?
  2. Where is the word in the string (beginning, middle, end)?

1.I search for word “Cal” right?

Yes, that is exactly right.

2.In the beggining right?

Yes. Again, absolutely correct.

And now what I should do

How do you write a regular expression to find a word? For example, find the word ‘dog’:

“my dog can jump high”

no no that:
/dog/gi???

Yes, but you don’t need the flags (gi), so just /dog/. Now how would you find the word ‘dog’ only at the beginning of a string?

‘dogs are wonderful pets’ << should match :white_check_mark:
‘my grandma hates dogs’ << should not match :no_entry_sign:

/dogs are wonderful pets/???