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

Поделиться
HTML-код
  • Опубликовано: 24 янв 2025

Комментарии • 122

  • @nikhilbankar4412
    @nikhilbankar4412 5 лет назад +22

    I've never seen a teacher as happy as you! thanks for making these videos.

  • @IrakliKhakhviashvili
    @IrakliKhakhviashvili 7 лет назад +4

    This guy has such a strong passion for teaching code that whatever he says just sticks to your brain without you even trying too hard.

  • @p1onier1986
    @p1onier1986 6 лет назад +17

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

  • @jumpmancw
    @jumpmancw 8 лет назад +62

    just so people know, the number 15 at the end is not the groups added together, it is the index of where the match starts in the string. If you match the first character of the string, that index will be 0.

    • @shilangyu
      @shilangyu 6 лет назад +12

      yeah, crazy how by accident it was the sum of the groups here too

    • @PaulJohnLeonard
      @PaulJohnLeonard 4 года назад +1

      Now that is useful.

  • @csababalogh777
    @csababalogh777 7 лет назад +7

    One of those rare videos on the internet that I want to like twice.

  • @shayanjavadi
    @shayanjavadi 8 лет назад +119

    myProfessors.replace(professor, Daniel Shiffman);

    • @StephenCurry-ff4zc
      @StephenCurry-ff4zc 7 лет назад +15

      myProfessors.replace(/myProfessors/, "Daniel Shiffman"); Should work now

    • @edgar-xavier
      @edgar-xavier 7 лет назад +1

      God, thank you for your service Stephen Curry!

    • @StephenCurry-ff4zc
      @StephenCurry-ff4zc 7 лет назад +1

      No problem. Always here to help

    • @vladanng
      @vladanng 7 лет назад

      You should be specialized on curying Stephen :)

    • @NitishPuri
      @NitishPuri 7 лет назад +7

      You forgot the global flag
      myProfessors.replace(/myProfessors/g, "Daniel Shiffman");

  • @naseemgharibi
    @naseemgharibi 6 лет назад

    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.

  • @itcertifications6066
    @itcertifications6066 3 года назад

    I wonder why are you so happy and super excited!!!!

  • @casperdewith
    @casperdewith 2 года назад +2

    I have a nice, simple application of applying functions for you:
    Suppose you have a text with timestamps in 12 h (am/pm) notation. Your task is to convert them to 24 h notation. You may assume that all timestamps have this format: 9:30 AM, 12:30 PM, 1:11 PM, etc. This should then become 9:30, 12:30, 13:11.
    I hope you like it! Converting AM to PM already is tricky.

  • @kandysman86
    @kandysman86 6 лет назад

    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.

  • @nocaster51
    @nocaster51 6 лет назад

    this tutorial got me more excited than it is usually necessary

  • @joelchacon9278
    @joelchacon9278 3 года назад +1

    Year 2021, ES6 has Rest parameters. It's preferred over the arguments object. He refers to it as the arguments array. :)
    This was a great video.

  • @moaazbhnas886
    @moaazbhnas886 8 лет назад +4

    It's my first time to complete an entire tutorial in one day without feeling bored .. you're awesome ❤️
    I'm sorry .. my English is not good 😅

  • @SuperCacazinho
    @SuperCacazinho 5 лет назад

    Guy, you're my favorite programmer youtuber.
    Thanks for helping me in this session so goodly.
    Greetings from Brazil :D

  • @yuvaraj8922
    @yuvaraj8922 3 года назад

    DUDE,YOU ARE A LIFE SAVER

  • @rron2084
    @rron2084 6 лет назад

    You're doing Gods work, Shiffman.

  • @HellYeah223
    @HellYeah223 7 лет назад

    Just got to 2.9 and it's totally worth it! Thank you Daniel

  • @peterchen1774
    @peterchen1774 7 лет назад

    Wow! I like Shiffman's enthusiasm!

  • @alexisarcegomez8698
    @alexisarcegomez8698 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!!!

  • @mrseidel
    @mrseidel 8 лет назад +6

    The numbers 15, 109, and 166 seem to align with the first character of each of the "group zeros" searched. i.e. string[15] = 9 from "999-1324", string[109] = 1 from '111-8765', etc.

    • @salty-horse
      @salty-horse 8 лет назад +3

      It's:
      "The offset of the matched substring within the whole string being examined. (For example, if the whole string was 'abcd', and the matched substring was 'bc', then this argument will be 1.)"
      Quoted from:
      developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/replace
      Daniel, why aren't you teaching how to read documentation? :) (I recommend pointing to MDN - Mozilla Developer Network, which is the best Javascript resource around. Even if it's not always super clear, it's a wiki and you can suggest changes).
      Poking around a blackbox is fun, but you might reach wrong conclusions.

  • @FrancescoMari1
    @FrancescoMari1 7 лет назад

    Having fun while doing regex :-) You're the best man in the world!

  • @loreleimcveen6134
    @loreleimcveen6134 8 лет назад

    You are an amazing teacher. You're also mad and I love it! Please keep up the great videos!

  • @AlishSafarli
    @AlishSafarli 2 года назад

    *17:02*
    _15 was the starting index of the first match. It was a coincidence resulting "15" to the total sum of lengths of the arguments inside a function_

  • @tentacle_sama3822
    @tentacle_sama3822 2 года назад

    6 years later this video still comes in handy

  • @AndiRHermawan
    @AndiRHermawan 7 лет назад

    thank you Daniel, you change my life

  • @longnthcmus
    @longnthcmus 8 лет назад +10

    15 is position of the matched number

  • @johnn4314
    @johnn4314 6 лет назад

    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

  • @raulcanuldzib7035
    @raulcanuldzib7035 7 лет назад

    Thank you very much, you saved me the semester. excellent video

  • @CameronChardukian
    @CameronChardukian 5 лет назад

    I've come back to watch this video so many times haha

  • @christianrodier3381
    @christianrodier3381 6 лет назад +1

    Thanks, I think many coders struggle w/ regexp and could always use more help.

  • @dever312
    @dever312 3 года назад

    This guy made it look easy. Yesssssssiiiiirrrrrskiiiii

  • @Adam-bs5bc
    @Adam-bs5bc 7 лет назад

    Just a quick question , Can i use wildcard somehow to manipulate text ??????

  • @47-movies11
    @47-movies11 4 года назад

    can substitution construct replace existing pattern to required pattern?

  • @DougKelleyDeveloperAccountant
    @DougKelleyDeveloperAccountant 4 года назад

    Hello, why does this work in splitting out numbers and text words per every capital letter?
    userNameStructure: any;
    const userName = '91MickeyMouse';
    this.userNameStructure = userName.replace(/([a-z0-9])([A-Z])/g, '$1 $2');
    console.log('words', this.userNameStructure);
    RESULT: words 91 Mickey Mouse
    My goal is to capture Mickey as first name, Mouse as last name. I was thinking I could call a function in place of '$1 $2', but that seems to fall apart.

  • @Anderson-tm1sl
    @Anderson-tm1sl 3 года назад

    I love your energy!

  • @apresthus87
    @apresthus87 5 лет назад

    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 :D

  • @shaharle88
    @shaharle88 4 года назад

    any advice how to split this string "n1->n2;n1->n3;goaln4;n4

  • @KCWonderWorld
    @KCWonderWorld 4 года назад

    What if I want to replace hypen from array of strings

  • @happykhan299
    @happykhan299 4 года назад

    Hi..can someone help me on my problem...how can I sort, filter and set ranges columnwise on notepad ++.. I am struggling to find the right solution for this issue I am facing..thank you in advance..

  • @marcohallister3966
    @marcohallister3966 3 года назад

    Thanks Buddy! You prevented me of converting 8k lines of code by myself.

  • @andreleox
    @andreleox 6 лет назад

    Nice class dude! Does anyone know is he putting himself foreground and laptop's background? What is this software? Thanks !

  • @balaumar100
    @balaumar100 4 года назад

    If a content or file contains "some value".I mean string like something is "fishy". How you match or handle tat quotes data with regex???

  • @mattambrogi6734
    @mattambrogi6734 4 года назад

    5:24, absolutely out of his mind..

  • @programmingpi314
    @programmingpi314 4 года назад

    How would you change the regex without just redefining it?

  • @ebraheemuthman7733
    @ebraheemuthman7733 2 года назад

    Quite educative and exciting. What is createP?

  • @yoho403
    @yoho403 3 года назад

    how would you do replace anything after "..."

  • @ArtemYershov-h1o
    @ArtemYershov-h1o Год назад

    It is fun and educating. Thank you )

  •  7 лет назад +7

    Just watched this whole series and it was mind boggeling :) Thank you for teching me Regular expressions, and I've been coding so long, and now I dont know how I can have lived without RegEx... :D
    Anyways, one question or problem to solve. When parsing a text for hashtags (#) on social media, I found that this: /(#\w+)/g works for finding any word that starts with a hash, BUT it also finds hashes that you might have in a normal url with an anchor. I know these arent frequently used anymore, but still, Id like to not find hashes inside other texts. And no matter how many \b I use or where I cant get it to ignore those. Adding a \s first kinda works, but then messes up rows that begin with a hashtag: here it is in action: regexr.com/3fkmn

    • @TheCodingTrain
      @TheCodingTrain  7 лет назад

      Great question! I think \b probably doesn't work b/c a slash is maybe a valid word boundary. Maybe you could try \s or ^ (beginning of line)?

    • @minhtricao706
      @minhtricao706 7 лет назад

      \B(\#\w+)\b should be the answer, but it doesn't solve the case; .......?#............

    •  7 лет назад

      Thank you Minh, this actually seems to work much better! :)

  • @cobacoba3598
    @cobacoba3598 6 лет назад

    how to store regular expression into sqlite?

  • @dembasiby
    @dembasiby 7 лет назад

    Great series! Thanks!

  • @aswinikonagalla4045
    @aswinikonagalla4045 2 года назад

    hi can you tell me regular expression for how to replace tag with tag

    • @palesathulo1964
      @palesathulo1964 2 года назад

      Did you find this? I’m looking to replace

    • @palesathulo1964
      @palesathulo1964 2 года назад

      Did you find this? I’m looking to replace

  • @riteshkavankar
    @riteshkavankar 4 года назад

    Thnaks you very much sir.
    We appreciate your efforts.
    There is one query,
    Plz tell me how I can avoid html tags while replacing text on html page.

  •  4 года назад

    Awesome, thanks!

  • @kentaylor6120
    @kentaylor6120 2 года назад

    Lovin P5.JS

  • @gnul
    @gnul 4 года назад

    ❤️❤️❤️❤️❤️👍👍👍👍
    This is very delicious what we learn here. 👨‍💻😋
    Exactly what I have needed.

  • @Mikeanddrea
    @Mikeanddrea 8 лет назад +3

    man you are hilarious hahaha 😂

  • @AssassininMinecraft
    @AssassininMinecraft 7 лет назад

    Love ur class :D

  • @noorfuadillah8927
    @noorfuadillah8927 5 лет назад

    Write down Regular Expressions that can extract Strings 123.jpg and 432.png from
    String axhdsjk123.jpg.jpg and hjhsd432.png.png
    How to?

  • @sanasayyed1830
    @sanasayyed1830 6 лет назад

    pls sir give me code for ana phora resolution in python

  • @galaxyexpress5943
    @galaxyexpress5943 4 года назад

    it is perfect 💥

  • @vincentm99
    @vincentm99 8 лет назад

    great vid :D, it's fun

  • @TheXtra3000
    @TheXtra3000 8 лет назад

    In atom there is a setting under the tab "Editor" which allows "Scroll Past End"

  • @DustinGunnells
    @DustinGunnells 6 лет назад

    OMG! This is useful!

  • @eminqasimovdev
    @eminqasimovdev 6 лет назад +2

    I would like to see you in strict mode

  • @federicotrotta968
    @federicotrotta968 3 года назад

    I thought to be quite good with RegExp but I didn't know about the lil secret of capturing group with split...

  • @TheCodingOdyssey
    @TheCodingOdyssey 4 года назад

    nice videos! Here's another example that I just came up with of what you could do with replace. let names = {
    Marian: "Superhero",
    John: "Rescuer",
    };
    names = JSON.stringify(names);
    names = names.replace(/"(\w+)":/g, `"new$1":`);
    console.log(JSON.parse(names)["newJohn"]);
    Whut you can do that with javascript? Niceee :)) or this:
    let names = {
    Marian: 2,
    John: 3,
    };
    names = JSON.stringify(names);
    console.log(names);
    names = names.replace(/:(\d+)/g, function () {
    return `:${arguments[1] * 2}`;
    });
    What?? Ha ha this is too fun.

  • @kearfy
    @kearfy 6 лет назад

    this is awesome 😂

  • @techslugz
    @techslugz 3 года назад

    REGEX! Baaaaybeeeeeeee yayaaah! :-)

  • @GamingBeast3
    @GamingBeast3 8 лет назад

    Regex.Replace("ThisIsACamelCaseString", "([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))", "$1 ") explain this code please

  • @47-movies11
    @47-movies11 4 года назад

    can you plz explain it?Please

  • @ryukikuga7460
    @ryukikuga7460 5 лет назад

    Those who have finished this guy's amazing Regular Expressions tutorial,
    Here is a good coding practice related to Regular Expressions from codewars!
    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~

  • @johnjackson3483
    @johnjackson3483 2 года назад

    My idea is have large completely normal looking document. Each space after each word would represent either a “1” or a “zero “ depending whether there are one or two spaces there thus hiding your binary program in the document.

  • @oscarvanvelsen7565
    @oscarvanvelsen7565 8 лет назад +1

    This dude has way less views than he deserves... Imma help U out and push your channel among my geek friends :)

  • @salty-horse
    @salty-horse 8 лет назад +2

    replace() with a function is very cool. I have used it in a Greasemonkey userscript that scans web pages for prices, and appends to them the price in your local currency:
    github.com/salty-horse/gm-scripts/blob/master/amazonLocalCurrency.user.js
    (It queries Yahoo's currency API once a day, and caches it in the greasemonkey registry)
    Other nice uses:
    1) Rudimentary templating system (although Javascript now has template literals with backticks)
    2) A simple way to escape text for inclusion in HTML. stackoverflow.com/a/1495837/16081
    It's generally useful whenever you do several calls to replace in a row: new_str = replace().replace().replace()

  • @TheOriginalDuckley
    @TheOriginalDuckley 8 месяцев назад

    The origin of the kittens song!

  • @reimarpb
    @reimarpb 6 лет назад

    You can also use replace() with a string instead of a regular expression

  • @Paul-q7q
    @Paul-q7q 10 месяцев назад

    I am the poor person watching it in the future😂😂😂,Thanks sir, understood clearly

  • @puppy_pope
    @puppy_pope 7 лет назад +2

    me at my grandma's house 5:23

  • @hannahmarques3422
    @hannahmarques3422 2 года назад

    Thank u

  • @binutil
    @binutil 8 лет назад +6

    Sorry no thumbs down :)

  • @mscottveach
    @mscottveach 8 лет назад

    Wow, Dan knows Jenny too!

  • @loic.bertrand
    @loic.bertrand 6 лет назад

    Kittens and kittens and kittens and kittens and kittens.... 😍 Kittens and rainbows and cupcakes 😂

  • @jakewood5475
    @jakewood5475 4 года назад

    What's to be excited about? yes regular expressions 😉

  • @emotionice7967
    @emotionice7967 5 лет назад

    'It replaced everything with blueberry. But do you realise whats now possible?'

  • @JBuchmann
    @JBuchmann 6 лет назад

    So the takeaway for me after this series of videos... RegEx is easy to write, yet difficult to read.

  • @Khan_2025
    @Khan_2025 6 лет назад

    thanks,

  • @CivReborn
    @CivReborn 7 лет назад

    I wonder how many people catch the 867 5309 ref

  • @Spacecakesupreme
    @Spacecakesupreme 5 лет назад

    there is chocolate and beer i guess

  • @RojusRzevuskis
    @RojusRzevuskis 7 лет назад

    No surprise someone did make it into a song. Check soundcloud

  • @xxnotmuchxx
    @xxnotmuchxx 7 лет назад +1

    Nice 127 Likes and 0 Dislikes.

  • @avitolourenco
    @avitolourenco 4 года назад +1

    Difference between $1 and /1

  • @nvmitsok
    @nvmitsok 4 года назад

    The comments were 101 but I'm evil

  • @motiurrahaman449
    @motiurrahaman449 2 года назад

    kittens and kittens and kittens.....😂🤣

  • @dmgGeronimo
    @dmgGeronimo 8 лет назад

    lol

  • @geoffwagner4935
    @geoffwagner4935 Год назад

    leprechauns