解析字串

const extractStr = (str) => {
  let result = [],
      pattern = /\:+(\w*)\.+/g,
      temp = null
  while(temp = pattern.exec(str)){
    result.push(temp[1])
  }
  return result
}

  例如:extractStr('My name is:Jerry. My age is:12.') // => ['Jerry', '12']

posted @ 2017-10-11 16:46  风吹麦浪打  阅读(210)  评论(0编辑  收藏  举报