JavaScript Split around curly braces

前端 未结 5 2235
再見小時候
再見小時候 2021-02-09 09:40

I have a string format inside of a string variable:

\"{0} Hello World {1}\"

I need to split it into something like this:

\"{0}\         


        
5条回答
  •  春和景丽
    2021-02-09 10:28

    You can do like this:

    var myregexp = /({.*?})(.*?)({.*?})/im;
    var match = myregexp.exec(subject);
       if (match != null) 
       {
         result1 = match[1];
         result2 = match[2];
         result3 = match[3];
       }
    

提交回复
热议问题