js使用正则表达式获取字符串中特定的字符

转自: [https://www.cnblogs.com/xiaohaifengke/p/11421208.html]

需求:从124fddr323532${xxxasdsafxx}253${bnm}23354${abcd}233545xx54${666}233545xxxxx这类字符串中获取${}中的内容。注意${xxx}的个数是不确定的。

   function getExecStrs (str) {
        var reg = /\$\{(.+?)\}/g
        var list = []
        var result = null
        do {
            result = reg.exec(str)
            result && list.push(result[1])
        } while (result)
        return list
    }

猜你喜欢

转载自www.cnblogs.com/ybixian/p/12370788.html