您的位置:首页 > 其它

[Regex Expression] Use Shorthand to Find Common Sets of Characters

2016-02-01 03:22 423 查看
In this lesson we'll learn shorthands for common character classes as well as their negated forms.

var str = `Afewserg, %8392 ?AWE`;

var regex = /[a-zA-Z0-9]/g;
// the same as:
var regex = /\w/g;

// Find anything but not the a-zA-Z0-9
var regex = /[^a-zA-Z0-9]/g;
// the same as
var regex = /\W/g;

var regex = /[0-9]/g;
// the same as:
var regex = /\d/g;

// Find anything but not the 0-9
var regex = /[^0-9]/g;
// the same as
var regex = /\D/g;

var regex = /\s/g; // match all the space

// Find anything but not the space
var regex = /[^\s]/g;
// the same as:
var regex = /\S/g;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: