search

Home  >  Q&A  >  body text

javascript - var str= 'asd,asd,12,321,,123,6,yrtv,x,z'; How many methods are there to obtain the numbers?

var str= 'asd,asd,12,321,,123,6,yrtv,x,z'; How many ways are there to get the numbers?

var str= 'asd,asd,12,321,,123,6,yrtv,x,z';

A regular method, use split to split into arrays. Is it possible to use the filter method of the array? Please solve it and write it down one by one. Thank you.
Example 1:

var reg = /\d+/g;
var str = "ss12345rr3432re232";
var ms = str.match(reg)
大家讲道理大家讲道理2714 days ago1060

reply all(2)I'll reply

  • 扔个三星炸死你

    扔个三星炸死你2017-06-28 09:28:30

    str.split(",").filter(a => a !== "" && !isNaN(+a))

    reply
    0
  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-06-28 09:28:30

    // 如果只要数字不分组的话,这个方法最简单
    str.replace(/[^\d]/gi, '')

    reply
    0
  • Cancelreply