Home  >  Article  >  Web Front-end  >  Detailed explanation of the use of the \D metacharacter (equivalent to "[^0-9]") in regular expressions

Detailed explanation of the use of the \D metacharacter (equivalent to "[^0-9]") in regular expressions

php中世界最好的语言
php中世界最好的语言Original
2018-03-29 10:52:113074browse

这次给大家带来正则表达式的\D元字符(等价于"[^0-9]")使用详解,使用正则表达式的\D元字符(等价于"[^0-9]")的注意事项有哪些,下面就是实战案例,一起来看一下。

\D元字符可以匹配非数字字符,等价于"[^0-9]"。

语法结构:

(1).构造函数方式:

new RegExp("\\D")

(2).对象直接量方式:

/\D/

浏览器支持:

(1).IE浏览器支持此方法。

(2).火狐浏览器支持此方法。

(3).谷歌浏览器支持此方法。

(4).opera浏览器支持此方法。

(5).safria浏览器支持此方法。

实例代码:

var str="I love antzone \n and you 360";
var reg=new RegExp("\\D","g");
console.log(str.match(reg));

以上代码可以匹配除数字之外的所有字符。

var str="I love antzone \n and you 360";
var reg=/\D/g;
console.log(str.match(reg));

此代码的作用和上面的代码是一样的。

相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

推荐阅读:

验证用户设置的密码强度正则表达式

lselect的option叠加问题如何解决

The above is the detailed content of Detailed explanation of the use of the \D metacharacter (equivalent to "[^0-9]") in regular expressions. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn