Split string with multiple separator in jQuery

If you want to split a string with multiple separators then you have to pass regex expression into split method. In below example I have used three character (, : -) as separator.

var numbers = '1,2:3-4';
var numArray = numbers.split(/,|:|-/);

<!DOCTYPE html>
  <title>jQuery With Example</title>
  <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
  <script type="text/javascript">
    $(function () {
      $('.btnClick').click(function () {
        var numbers = '1,2:3-4';
        var numArray = numbers.split(/,|:|-/);

        for (var i = 0; i < numArray.length; i++) {

    <button class="btnClick">Click</button>



  1. Replies
    1. Hi Aksa,
      If you want to split a string with multiple separator.
      Suppose your string is "I-love-my,country,India".
      In this string there are two separator dash(-) and comma(,).
      Then you have to write code like this.

      var allword = 'I-love-my,country,India';
      var wordArray = allword .split(/,|-/);

      Above split method I have used regex expression, split method return an array.
      In regex expression it start and end with "/".
      After that enter your each separator with "|".

  2. hi nirbhay singh bro how can use dropdwonlist along with grid view using jquery

  3. I admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much. Day Trips From Split

  4. I am very thankful to you that you have shared this information with us. I got some different kind of knowledge from your web page, and it is really helpful for everyone. Thanks for share it. niagra falls helicopter ride