I'm using the NewsApi API as content for a Typing Tutor app, which requires replacing characters that are not easily inputted (specifically, ’, —,“,”, which need to be replaced with ',-,",", respectively).
I suspect the strings coming through are somehow encoded because the javascript string.replace() function is not working on strings pulled directly from the HTTP responses - it only works if I copy-paste the relevant strings from the API responses in the browser network tools or from Postman.
Code
(in practice the string is pulled from the NewsApi API but it is a difficult issue to replicate as the news headlines are always changing...)
var string = "you’re"
string = string.replace(/’/,`'`)
console.log(string)
Expected Output
This only happens when the string is copy-pasted from browser console or postman:
>> you're
Actual Output
>> you’re
// note the apostrophe has a direction (not vertical) and
// therefore can't be easily typed
EDIT: there was a spurious space in the regex before the apostrophe. This was a typo in the question - not in the original codebase - and has now been fixed.
"you’re".replace(/’/,')works well. Without more details or a minimal reproducible example, there is nothing we can help you with.