Why do they use
/
instead of
‘
in JavaScript string replace()? E.g.:
document.write(str.replace(/hi/, "hey"));
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
because // denotes a Regex, which is a much more powerful version of string searching/replacing than a simple Replace(“x”,”y”)
But also supports simple patterns.
adding the g modifier to replace globaly would be:
You can also add the i modifier to make it case-insensitive.
https://developer.mozilla.org/En/Core_JavaScript_1.5_Guide/Regular_Expressions