Matrix given in brackets {{2,3},{4,5}}
Need regular to get 0=> 2,3 1=> 4,5
Further, I will break it down by commas.
He could only get {{2,3} and {4,5} , cut the brackets I think is wrong, so I need help with the correct regular schedule.

  • there is probably not a regular one, but a parser. {{2,3}, {4,5}} resembles JSON - although it may be necessary to replace curly brackets with square brackets. - Mirdin
  • no, just like brackets. JSON has a parameter: value. There is no. - sinneren
  • Specify the preferred language (not indicated in the tags and in the question too). Regular is good. Only in one case you need to use split in the other replace and in the third exec. - nick_n_a
  • 2
    If you need a two-dimensional array, then the string itself is not necessary to parse. replace braces with square brackets, get an array in JS format. var a=eval("{{2,3},{4,5}}".replace(/{/g,'[').replace(/}/g,']')) - Mike
  • 2
    For solving this problem, the regular /\{([^{}]*?)\}/g - it will subtract all non-brackets inside curly brackets. But decisions aren't vlob - more graceful) - Mi Ke Bu

2 answers 2

 var s = "{{2,3},{4,5}}"; var a1 = s.split(var a1 = s.split(/\{\{|\}\}|\}\,\{/g );//Разбить на два alert(a1.join('][') ); //[][2,3][4,5][] var a2 = s.split(/[\{\}\,]+/g ); // Разбить на четыре (исправил) alert(a2.join('][') ); // [][2][3][4][5][] 

Instead of WScript.Echo in the browser, you need alert (). How to remove the first and the last is empty - I can not say

  • Then we get ["", "", "3", "4", "", "", "2", "1", "", ""] and not 0 => 2.3 1 => 4 , 5 - sinneren
  • I understood that for the browser regex works a little differently, now I will add other options. - nick_n_a
 eval($('#matrix-data').val().replace(/{/g,'[').replace(/}/g,']'));