0

I have number of strings like

var str="#{ZyDt8spGZOA.mI8uHaT7o47}+#{z3PENrRf0cn.mI8uHaT7o47}+#{lhUBSvCMPWu.mI8uHaT7o47}+#{YNpiWU7fw9m.mI8uHaT7o47}";

I need to get the content only inside the curly bracket to an array. (In the above case array of length 4).

How can I achieve this?

assylias
  • 321,522
  • 82
  • 660
  • 783

2 Answers2

1

use following code

array = str.split("}+#{");

after doing this reult will look like

array[0] = "#{ZyDt8spGZOA.mI8uHaT7o47"  
array[1] = "z3PENrRf0cn.mI8uHaT7o47"  
array[2] = "lhUBSvCMPWu.mI8uHaT7o47"  
array[3] = "YNpiWU7fw9m.mI8uHaT7o47}" 

after this just remove extra string form array[0] and array[3]

array[0] = array[0].substring(2, array[0].length)
array[3] = array[3].substring(0, array[3].length-1)

Community
  • 1
  • 1
Rahul Bhawar
  • 450
  • 7
  • 17
1
    var found = [],          
    rxp = /{([^}]+)}/g,
    str = "#{ZyDt8spGZOA.mI8uHaT7o47}+#{z3PENrRf0cn.mI8uHaT7o47}+#{lhUBSvCMPWu.mI8uHaT7o47}+#{YNpiWU7fw9m.mI8uHaT7o47}",
    mat;

    while( mat = rxp.exec( str ) ) {
          found.push(mat[1]);
    }

    alert(found); 
SatyaTNV
  • 4,137
  • 3
  • 15
  • 31