首页 > 其他 > 详细

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

时间:2016-02-01 09:32:55      阅读:104      评论:0      收藏:0      [点我收藏+]

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;

 

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

原文:http://www.cnblogs.com/Answer1215/p/5174335.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!