2.8: Regular Expressions: split() - Programming with Text

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 พ.ย. 2024

ความคิดเห็น •

  • @rotrose7531
    @rotrose7531 4 ปีที่แล้ว +2

    The idea of using s.split(/[.\s]+/) to fix unnecessary blank is simply amazing! Best programming teacher across the whole youtube.

  • @falkelh
    @falkelh 3 ปีที่แล้ว +6

    Thanks so much for this. I spent the whole day yesterday trying to do what you showed me here!

  • @laxris
    @laxris 8 ปีที่แล้ว +17

    I just want to note something because it got me confused for a sec. On this video @4.00 the split function has been called "s.split(/[,\s/]+/);" with an extra forward slash inside the group in square brackets. This will just add to delimiters the forward slash, is not escaping the right square bracket. Even if it was back slash it wouldn't (most likely it would be syntax error). Just in case this will be useful to anyone.

    • @ronaldc8634
      @ronaldc8634 6 ปีที่แล้ว +2

      yes I got confused about that and had to check. s.split(/[,\s]+/) will also be the same thing

    • @RahulSharma-oe6fy
      @RahulSharma-oe6fy 2 ปีที่แล้ว

      Thank you ! You are a saviour

  • @mluevanos
    @mluevanos 8 ปีที่แล้ว +8

    Love the series on RegEx, good stuff.

  • @wxIyz
    @wxIyz 8 ปีที่แล้ว +1

    la mejor explicacion que he visto sobre expresiones regulares :D

  • @DanielRicardo42
    @DanielRicardo42 7 ปีที่แล้ว +4

    Your videos are great, but you should look into using the forEach() loop - that would save you so much time and typing, and would make your code more readable.
    For example, instead of:
    for (var i = 0; i < words.length; i++) { createP(words[i]; }
    You can just write:
    words.forEach(function(word) { createP(word) } )

    • @TheCodingTrain
      @TheCodingTrain  7 ปีที่แล้ว +3

      Heh, I get this comment a lot! Ok, I will use it in a video soon!

    • @FrenchMajesty
      @FrenchMajesty 7 ปีที่แล้ว +3

      If you're only doing one thing a better syntax for a forEach would be:
      words.forEach(word => createP(word));

    • @DanielRicardo42
      @DanielRicardo42 7 ปีที่แล้ว +3

      Yeah, but I preferred not to confuse other readers with arrow functions, since they are less readable, and take more explanation to understand. One thing at a time.

  • @cnkadgn9745
    @cnkadgn9745 ปีที่แล้ว

    How can i extract the last word in a cell? I dont get it. I would be glad for any help. Greetings from germany

  • @ΑναστάσηςΤσαμπούκος
    @ΑναστάσηςΤσαμπούκος 2 ปีที่แล้ว

    I am currently trying to make something similar with a chatting app, where the # symbol with the word following with be the tags for the post I just don't know the correct regex in order to split and get the different # as tags

  • @priyanksharma1518
    @priyanksharma1518 6 ปีที่แล้ว

    what if the string starts with a special character then can we split it and get only the tokens.Tokens are sequence of alphabets.

  • @LotfiORouis
    @LotfiORouis 4 ปีที่แล้ว

    What a wonderful guy!

  • @benaya6
    @benaya6 5 ปีที่แล้ว

    how much of it is the same with java instead of javascrips??

  • @the_sweet_heaven
    @the_sweet_heaven 4 ปีที่แล้ว

    Nice video, thanks

  • @anbuanbu6591
    @anbuanbu6591 6 ปีที่แล้ว

    how to extract before and after two words from particular string using regular expression and c#???

  • @pradeepnayak4341
    @pradeepnayak4341 3 ปีที่แล้ว

    "1.JavaScript String function. 2.which is used to split a given piec. 3.defined by a regular expression."
    output:["1.JavaScript String function.","2.which is used to split a given piec.","3.defined by a regular expression."]
    please send the regx code

  • @michikoshin9309
    @michikoshin9309 ปีที่แล้ว

    Thanks.

  • @ahmad-ali14
    @ahmad-ali14 5 ปีที่แล้ว

    you are the best

  • @dustinkftw
    @dustinkftw 5 ปีที่แล้ว

    This might be a dumb question, but where does the forward-slash come from at the beginning and at the end of the Regex?

  • @SriNooka
    @SriNooka 3 ปีที่แล้ว

    Print the characters in a string separated by comma. i need the word run to get as r,u,n can anyone help me plz??

    • @rf8349
      @rf8349 2 ปีที่แล้ว

      "run".split("").join()

  • @edilsonfb
    @edilsonfb 7 ปีที่แล้ว

    Just awesome!

  • @venusirpuram4345
    @venusirpuram4345 4 ปีที่แล้ว +10

    By seeing the thumbnail of this video I thought that Sundar Pichai is teaching regex

    • @sleep3017
      @sleep3017 4 ปีที่แล้ว +1

      He kinda looks like him

  • @travelpost1656
    @travelpost1656 6 ปีที่แล้ว

    Hi how do i use same regular expression and split on word 'and' along with other symbols like comma,& etc. right now i have split(/[ ,&]+/) and i want to add "and" word as separator along with other symbols

  • @ebsibakennady5737
    @ebsibakennady5737 6 ปีที่แล้ว

    String line = first, second,"hello,world","one,""two"""
    line.split(",(?=([^\"]|\"[^\"]*\")*$)");
    the output is first second hello, world one,two
    can you please explain how this regular expression working?

    • @trolololo720
      @trolololo720 6 ปีที่แล้ว +1

      First, it looks for a comma.
      Then, it looks ahead and makes sure that it's followed by
      - anything but a quotation mark
      or
      - quotation mark, anything but a quotation mark (0 or more times) and another quotation mark
      0 or more times, and always followed by the end of a line.

  • @Shecandoitsir
    @Shecandoitsir 4 ปีที่แล้ว

    How to do this const a=“[{name:”bob”},{name:”ron”}]”;
    Expected out put: [{name:”bob”},{name:”ron”}]
    Thank you

    • @Fun-Planet
      @Fun-Planet 4 ปีที่แล้ว

      JSON.parse(a)

  • @nhimxanh3807
    @nhimxanh3807 4 ปีที่แล้ว

    hi. Can someone help me ?
    I don’t know how to replace word with hyphen. e.x: from “a-b” to “b-a”.

  • @suvendubiswal6820
    @suvendubiswal6820 3 ปีที่แล้ว

    I need to fetch half of the value of the full string!(without if else) Now think 1000 times and then reply here i know you will be failed in this case.

  • @devarshmodi2732
    @devarshmodi2732 5 ปีที่แล้ว

    Can you pls give me regex which runs on regex tester ?!