Using the String.replace() method - JavaScript Tutorial
ฝัง
- เผยแพร่เมื่อ 2 ต.ค. 2024
- In today's video I'll be demonstrating the use of the String.replace() method within JavaScript including covering it's more advanced usage. This includes regular expressions, capture groups and using a function as the third parameter.
Support me on Patreon:
/ dcode - with enough funding I plan to develop a website of some sort with a new developer experience!
For your reference, check this out:
developer.mozi...
Follow me on Twitter @dcodeyt!
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
#dcode #javascript #webdev
So, tell me about your thing for older women. :P
Can make a feed back form of the user**** that actually we can see.**** If we can please make a tutorial on it****
****Only html css and java script
Thanks for your video though it will take someone with sound knowledge of RegEx or quite brilliant to understand you. 😁
I was an excellent video, but I would have liked to see you grouping up a string with no numerical value. I mean, no numbers in it. If you could tell me how, I'd appreciate it.
no clue how \d+ equals the first number?
another amazing video. your youtube videos are better than your udemy class. Why you are not making a professional class on HTML, CSS and Javascript on udemy
This is nice, but not very practical, can you show an example of removing a reoccurring section of text/string from within an array of objects? Example [{ page: { results: [{ title: 'keep this - textI dont want' }, {keep this - difftextI dont want}, {keep this - diffdifftextI dont want} ]}}]
6:15 uhhhh hey, i'm 31 and she's 21 $!
Hello! How do you get rid of everything after a semicolon?
Hello, is there an easy way to replace some text from a string to an html tag ?
Thank you in advance for your answer :)
let newPhrase = document.querySelector(".phrase");
let myString = "Wrap Html Tags around this string of text";
let textFragment = myString.replace(/html tags/gi, () => {
return `YOUR MIND`;
});
newPhrase.innerHTML = textFragment;
// The output would read "Wrap YOUR MIND around this string of text"
// Note that "YOUR MIND" is italicised
Did not know about console.log(arguments). Very useful
Finnaly I understood how to replace a lot of letters from my strip. THANKS a lot and greetings from Colombia.
A regular expressions video would be nice
Your videos are very helpful.
Why TH-cam didn't remove outline for the "Like" button ?!?!?!?
thanks
Awesome stuff!
Hi ! Whats the point of the plus sign after the d?
Never HEard of this
Waiting for the RegEx series! 🙌🏼🙌🏼🙌🏼
superb vdo thank you
Instead of using parseInt at the end you could also use a template literal: return `${g1 + g3}` or if you want it to use the groups to make more sense to the reader: return `${g3} ${g2} ${g1 + g3}`. Also, if you don't need to print the arguments you can convert your function to an arrow function making it more concise: console.log(myStr.replace(/(\d+)([^\d]+)(\d+)/g, (match, g1, g2, g3) => `${g3} ${g2} ${g1 + g3}`));
:)
awesome
Really good video
Thanks mate
great vif
Glad you liked it