Replace string in javascript with examples including regular expression REGEX

Pubblicato il: 21 gennaio 2023
sul canale di: Tech Nursery
109
1

In this video, we are discussing How to replace a character,a substring or group of characters from a string variable in javascript

1. Replace a character from a variable with empty character
2.Replace a sub string from a variable with empty character
3.Replace a set of characters from a variable with empty character


Here we replace character 'e' from string 'Technursery' by calling blogName.replace('e', '') .It will replace first occurrence of 'e' from the string 'Technursery'

const blogName = 'Technursery';

const blogNameWithoutVowels = blogName.replace('e', '');

console.log(blogNameWithoutVowels);

Here we are replacing all vowels characters aeiou from the given string using regular expression REGEX.By executing blogName.replace(/[aeiou]/gi, '') we will get the string without all vowels aeiou

const blogName = 'Technursery';

const blogNameWithoutVowels = blogName.replace(/[aeiou]/gi, '');

console.log(blogNameWithoutVowels);

Here we replace a substring with empty string in javascript. When we execute blogName.replace('Tech', '') it will replace substring Tech with empty string

const blogName = 'Technursery';

const blogNameWithoutVowels = blogName.replace('Tech', '');

console.log(blogNameWithoutVowels);


In questa pagina del sito puoi guardare il video online Replace string in javascript with examples including regular expression REGEX della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Tech Nursery 21 gennaio 2023, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 109 volte e gli è piaciuto 1 spettatori. Buona visione!