JavaScript Regex: How to split Regex subexpression matches in to multi-dimensional string arrays?

前端 未结 3 1179
温柔的废话
温柔的废话 2021-01-03 14:15

How would you split Regex subexpression matches in to multi-dimensional string arrays?

I have a \"myvar\" string of:

1-4:2;5-9:1.89;10

3条回答
  •  無奈伤痛
    2021-01-03 15:01

    The simpliest way to do it - using split method of String:

    var myvar = "1-4:2;5-9:1.89;10-24:1.79;25-99:1.69;100-149:1.59;150-199:1.49;200-249:1.39;250+:1.29";
    myvar.split(';');
    

    that produced:

    ["1-4:2", "5-9:1.89", "10-24:1.79", "25-99:1.69", "100-149:1.59", "150-199:1.49", "200-249:1.39", "250+:1.29"]
    

提交回复
热议问题