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.
|
2 answers
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,']')); |
var a=eval("{{2,3},{4,5}}".replace(/{/g,'[').replace(/}/g,']'))- Mike/\{([^{}]*?)\}/g- it will subtract all non-brackets inside curly brackets. But decisions aren't vlob - more graceful) - Mi Ke Bu