Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created November 21, 2017 07:23
Show Gist options
  • Save ThaddeusJiang/7072ecce50993a90ff63595c56e8a3f8 to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/7072ecce50993a90ff63595c56e8a3f8 to your computer and use it in GitHub Desktop.
使用正则表达式取出字符串中特定部分。

()表示子表达式,子表达式可以获取供以后使用。

function getParam(value) {
  var reg = new RegExp('^name=([\\s\\S]*)$');
  var result = value.match(reg);
  return result != null ? result[1] : null;
}

console.log(getParam('name=jifa'));

result 是一个大小为2的数组, result[0] = 'name=jifa' result[1] = 'jifa'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment