Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
string.replace IntelliSense is conveying wrong meaning #41361
Comments
To perform a global replacement you have to use Regex: Js ref var str = "Mr Blue has a blue house and a blue car";
var res = str.replace(/blue/gi, "red"); But yes, the IntelliSense doc is confusing. |
Only correcting the documentation is a viable option. TypeScript does not provide the |
- * @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
+ * @param replaceValue A string containing the text to replace the first successful match of searchValue in this string. |
Created a PR with updated documentation. |
If you use a regex for replacing all occurrences, then "text to replace the first successful match of searchValue in this string" will also become confusing. I suggest that the doc clearly convey 2 options for the
|
|
More like: Might also use "first occurrence" in place of "first successful match". |
Updated it accordingly. |
TypeScript Version: 4.1.0-beta
Search Terms: string.replace
Code
Expected behavior: It should replace all occurrences of 'apple'
Actual behavior: It is replacing only the first occurrence of 'apple'.

Either correct the IntelliSense doc or fix the replace function. Please find the attached screenshot below
Playground Link: https://www.typescriptlang.org/play?target=99&ts=4.1.0-beta#code/FDDGHsDsGcBcAI4Cd4F4DkBDADtgNgKbw74HoDcw81NtNEM4hAdHuAOYAUyzSB+mUAU5ZchdABp04JJkjsC0dAEpllKvCA
Related Issues: None
Issue raised by amityadav.java@gmail.com