2.9: Regular Expressions: replace() – Programming with Text

27
2



In this video, I cover the JavaScript function replace(). The function allows you to search for a string (by matching a regular expression) and replace that string. The replacement can be a literal string itself or you can pass in a callback where you can use logic and programming to generate a replacement string based on anything you can imagine.

This is the ninth video in a series on Regular Expressions, which is part of the “Programming from A to Z” course at ITP (

Next Video:

Course url:

Support this channel on Patreon:

Send me your questions and coding challenges!:

Contact:

GitHub Repo with all the info for Programming from A to Z:

Links discussed in this video:
MDN’s Regular Expressions Reference:
Regular Expressions on Wikipedia:
Book Mastering Regular Expressions:
ITP from Tisch School of the Arts:

Source Code for the all Video Lessons:

p5.js:
Processing:

For More Programming from A to Z videos:

For More Coding Challenges:

Help us caption & translate this video!

📄 Code of Conduct:

Nguồn:https://wijstaanvooronzegrondrechten.org/

Xem Thêm Bài Viết Khác:https://wijstaanvooronzegrondrechten.org/cong-nghe

27 COMMENTS

  1. Guy, you're my favorite programmer youtuber.

    Thanks for helping me in this session so goodly.
    Greetings from Brazil 😀

  2. Those who have finished this guy's amazing Regular Expressions tutorial,
    Here is a good coding practice related to Regular Expressions from codewars!
    https://www.codewars.com/kata/valid-phone-number/train/javascript

    It's always good to try to implement skills you just learned and try to use them in order to solve something!
    Keep it up guys~

  3. I used regex to seperate out half moves in chess to different capture groups from PGN files, to create a PGN viewer ( a chess game replayer) in JS 🙂 I love regex now, it saved me so much headache 😀

  4. Write down Regular Expressions that can extract Strings 123.jpg and 432.png from

    String axhdsjk123.jpg.jpg and hjhsd432.png.png

    How to?

  5. Here's a useful way to get a Date object easily using RegExp.

    function getDate (str) {
    const matcher = /d{1,2}-d{1,2}-d{4}/;
    const match = matcher.exec(str);
    return new Date(match[3], match[2], match[1]);
    }

  6. Very usefull, now I finally can say that I've learned about RegEx whit your tutorials series. Thank you very much teacher Danniel, regards from Mexico :-). YOU ARE THE BEST!!!

  7. This video just triggered a Eureka moment in my brain. I'm 35 and just started learning coding 4 months ago and I think I've just turned a corner. Thank u man. I'm not sure what u did, but it's like a fog has just lifted off of javascript for me.

  8. very useful tutorials….I've spent 4 hours trying to solve a problem, after watching your video I solved it within 2 minutes !!!

  9. function imprim(){
    var t5= ''
    ctx.font = "Arial 14px"
    positionY= 50
    while( count< canvas.height/2){
    ctx.fillText(t1,200,positionY)

    positionY= positionY + 10
    count = count +1}
    function replace(t1){
    var t5 = t1.replace(/t1/g,"php")
    }

    var t1= ' Hello javascript'
    undefined
    var t2= t1[3]
    undefined
    var t3 = t1.length
    undefined
    count=0
    0
    help me please

  10. is it possible to say I want regex to capture a,b and c, but replace a with a certain section of a, replace be with a certian section of b, and replace c with a certain section of c… I was thinking that | would be used in the match part of the replace , but I havent found a decent example

  11. that was an amazing tutorial, i didn't even noticed that i'm watching the last one.
    in few hours i watched all your videos and i'm so thankful to learn from you.
    greetings from Syria
    you are the best.

LEAVE A REPLY

Please enter your comment!
Please enter your name here