This video covers split() — a JavaScript String function, which is used to split a given piece of text into “tokens” based on a “delimiter” as defined by a regular expression.

This is the eighth 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!:


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:


For More Programming from A to Z videos:

For More Coding Challenges:

Help us caption & translate this video!

📄 Code of Conduct:

Nguồn: https://androidsvn.com

Xem thêm bài viết khác: https://androidsvn.com/lap-trinh-php/



22 thoughts on “2.8: Regular Expressions: split() – Programming with Text

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

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

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

  4. 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

  5. String line = first, second,"hello,world","one,""two"""
    the output is first second hello, world one,two
    can you please explain how this regular expression working?

  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.

  7. It's driving me nuts! When we split it up by spaces, commas and dots, there is an empty item at the very end. How do you get rid of this!? You had it too, but you did not comment on it.

    var array = text.split(/[.,s]+/);

  8. 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) } )

  9. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *