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

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

小云云
Release: 2023-03-19 15:28:02
Original
2902 people have browsed it

\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));
Copy after login

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


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

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

相关推荐:

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template