zl程序教程

您现在的位置是:首页 >  其它

当前栏目

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

to of Find use Common expression characters regex
2023-09-14 08:59:20 时间

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;