3

The following replacement

"index.html".replace('\.html$', '_fr.html');

returns "index.html", indicating that the first argument didn't match anything. However, if I remove the "$"

"index.html".replace('\.html', '_fr.html');

then the first argument matches and "index_fr.html" is returned.

Returning to the first example, can someone explain why ".html$" does not seem to match "index.html"?

1 Answer 1

5

Because that's not a regular expression - regex literals in JavaScript look like:

/\.html$/

without quotes. String.replace takes a string or a regular expression literal.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.