regex between two special characters

后端 未结 6 1228
花落未央
花落未央 2021-01-26 11:12

Is there a way to replicate this PHP snippet in JQuery or Javascript...



        
6条回答
  •  感情败类
    2021-01-26 11:28

    Regex are pretty much the same across all languages. If you want to get everything in between {} and put it into an array you can do this:

    var arr = [];
    var str = 'Lorem {ipsum dolor} sit {amet} conseteur {adipisci}';
    str.replace(/{(.+?)}/g, function(a, b){ arr.push(b) });
    
    console.log(arr); //=> ["ipsum dolor", "amet", "adipisci"]
    

    Demo: http://jsfiddle.net/elclanrs/xeHZn/

提交回复
热议问题