JavaScript 正则提取字符串

@bingoogolapple 2017-06-08 18:33:21发表于 bingoogolapple/bingoogolapple.github.io FE

let str = 'abcdefgname="test"sddfhskshjsfsjdfps'
let reg = /name="((\w|-|\s)+)/ig
str.replace(reg, function() {
  console.log(arguments)
  console.log(arguments.length)
  console.log(arguments[1])
})

console.log('\n---------------------------\n')

str = 'url(http://localhost:8080/%E4%B8%AD%E7%A7%8B…4%BB%E5%8A%A8/banner.jpg);'
let aar = /url\((.+)\)/.exec(str)
console.log(aar)
aar = /url\((\S+)\)/.exec(str)
console.log(aar)

console.log('\n---------------------------\n')

str = 'TypeError: Cannot read property \'length\' of undefined\n    at o.submit (http://localhost:18080/static/js/13.d54f45b1cc087699157a.js:1:3641)\n    at o.n [as submit] (http://localhost:18080/static/js/vendor.9393104e7831a4c3874e.js:6:664)\n    at click (http://localhost:18080/static/js/13.d54f45b1cc087699157a.js:1:5886)\n    at o.t (http://localhost:18080/static/js/vendor.9393104e7831a4c3874e.js:6:5222)\n    at o.e.$emit (http://localhost:18080/static/js/vendor.9393104e7831a4c3874e.js:6:56660)\n    at o.handleClick (http://localhost:18080/static/js/vendor.9393104e7831a4c3874e.js:11:361888)\n    at n (http://localhost:18080/static/js/vendor.9393104e7831a4c3874e.js:6:652)\n    at HTMLButtonElement.t (http://localhost:18080/static/js/vendor.9393104e7831a4c3874e.js:6:5222)'
aar = /http(.+).js/.exec(str)
console.log(aar)
aar = /http(\S+).js/.exec(str)
console.log(aar)