RegEx to extract all matches from string using RegExp.exec

前端 未结 17 1186
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:49

I\'m trying to parse the following kind of string:

[key:\"val\" key2:\"val2\"]

where there are arbitrary key:\"val\" pairs inside. I want t

17条回答
  •  鱼传尺愫
    2020-11-22 03:03

    Here is my answer:

    var str = '[me nombre es] : My name is. [Yo puedo] is the right word'; 
    
    var reg = /\[(.*?)\]/g;
    
    var a = str.match(reg);
    
    a = a.toString().replace(/[\[\]]/g, "").split(','));
    

提交回复
热议问题