什么是正则表达式
Last updated
Was this helpful?
Last updated
Was this helpful?
Was this helpful?
// 校验是否是纯数字
/^[\d]+$/.test('100'); // true
/^[\d]+$/.test(100); // true
/^[\d]+$/.test('abc100'); // fals// 把“-”替换为“@”
'nxtech-regexp'.replace(/\-/g, '@'); // nxtech@regexp
// 删除字符串中的空格
'一 起 学 RegExp'.replace(/\s/g, ''); // "一起学RegExp"// 从字符串提取纯数字字符串
'abc123abc'.match(/[0-9]+/); // 123
// 从url中提取查询参数,下述从qq地址中提取参数参数name的值
'http://www.qq.com?name=qq'.match(/(?:\?|&)name=([^&]*)/); // [0: '?name=qq', 1: 'qq', ...]