Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
YouTube Security VideosGoogle Chrome: Unfinished Projects by Chrome: Joe Burrow’s Chess Set(21.09.2026 um 16:05 Uhr)
YouTube Security VideosGitHub: How to move AI from code completion to agentic workflows(21.09.2026 um 17:00 Uhr)
YouTube Security VideosGoogle Workspace: Why are we like this 😭 #Shorts(21.09.2026 um 16:15 Uhr)
Windows Tipps & SecurityNeues Elektroauto von Rolls-Royce wird äußerst exklusiv sein(21.09.2026 um 16:46 Uhr)
Windows Tipps & SecurityGooglebooks überraschen: Die beste KI-Funktion ist gar keine KI(21.09.2026 um 16:59 Uhr)
YouTube Security VideosGoogle Chrome: Unfinished Projects by Chrome: Joe Burrow’s Chess Set(21.09.2026 um 16:05 Uhr)
YouTube Security VideosGitHub: How to move AI from code completion to agentic workflows(21.09.2026 um 17:00 Uhr)
YouTube Security VideosGoogle Workspace: Why are we like this 😭 #Shorts(21.09.2026 um 16:15 Uhr)
Windows Tipps & SecurityNeues Elektroauto von Rolls-Royce wird äußerst exklusiv sein(21.09.2026 um 16:46 Uhr)
Windows Tipps & SecurityGooglebooks überraschen: Die beste KI-Funktion ist gar keine KI(21.09.2026 um 16:59 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

JavaScript `string.replace()` useful cases

1. Simple String Replacement Replace the first occurrence of a substring. let str = "Hello world!"; let result = str.replace("world", "JavaScript"); // Output: "Hello JavaScript!" 2. Global String Replacement Replace…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




1. Simple String Replacement



Replace the first occurrence of a substring.




let str = "Hello world!";
let result = str.replace("world", "JavaScript");

// Output: "Hello JavaScript!"









2. Global String Replacement



Replace all occurrences of a substring, use the global (g) flag with regular expression.




let str = "Hello world, world!";
let result = str.replace(/world/g, "JavaScript");

// Output: "Hello JavaScript, JavaScript!"










3. Case-insensitive Replacement



You can make the replacement case-insensitive using the i flag.




let str = "Hello World, World!";
let result = str.replace(/world/gi, "JavaScript")

// Output: "Hello JavaScript, JavaScript!"









4. Replace Whole Words (Word Boundary)



Replace only whole words using \b word boundary.




let str = "This is a test word, test.";
let result = str.replace(/\btest\b/, "success");

// Output: "This is a success word, test."






Replace all occurrences of the whole word, use the global flag.




let str = "This is a test word, test.";
let result = str.replace(/\btest\b/g, "success");

// Output: "This is a success word, success."









5. Using a Function for Replacement



You can pass a function to replace() that dynamically generates the replacement string.




let str = "The price is $10";
let result = str.replace(/\$\d+/g, (match) => {
return `$${parseInt(match.substring(1)) * 2}`
});

// Output: "The price is $20"









6. Capturing Groups with Replacement



Using regular expressions, you can capture parts of the match and reuse them in the replacement string.




let str = "John Smith";
let result = str.replace(/(\w+)\s(\w+)/, "$2, $1");

// Output: "Smith, John"









7. Escaping Special Characters



If you need to replace special characters like . or *, you need to escape them in the regular expression.




let str = "Price: 5.99";
let result = str.replace(/\./, ",");

// Output: "Price: 5,99"









8. Replacing Non-ASCII Characters



To replace characters that aren't in the ASCII range, you can use Unicode properties.




let str = "Héllo Wörld";
let result = str.replace(/[^\x00-\x7F]/g, "");

// Output: "Hllo Wrld"









9. Replacing Digits



You can replace digits (or groups of digits) using regular expressions.




let str = "Contact: 123-456-7890";
let result = str.replace(/\d{3}/g, "***");

// Output: "Contact: ***-***-***0"









10. Replacing Special Characters using Unicode



You can also use Unicode escape sequences to replace special characters.




let str = "I love ☕!";
let result = str.replace(/\u2615/g, "coffee");

// Output: "I love coffee!"


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten JavaScript `string.replace()` useful cases

Thematisch verwandte Begriffe: JavaScript, stringreplace, useful, cases · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-94393 | When a user creates or edits a report inside an event, MISP can identify…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick