Home  >  Article  >  Backend Development  >  Detailed explanation of regular expression \D metacharacter (equivalent to "[^0-9]")

Detailed explanation of regular expression \D metacharacter (equivalent to "[^0-9]")

小云云
小云云Original
2018-01-20 09:36:542870browse

\D元字符可以匹配非数字字符,等价于"[^0-9]"。本文主要介绍正则表达式 \D 元字符的相关资料,需要的朋友可以参考下,希望能帮助到大家。

\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));

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

相关推荐:

正则表达式元字符和普通字符详解

JS正则表达式完美实现身份证校验功能

JS 正则表达式用法的详细介绍

The above is the detailed content of Detailed explanation of regular expression \D metacharacter (equivalent to "[^0-9]"). 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