X
HOME HTML5 CSS3 JAVASCRIPT SQL PHP5 JQUERY ANGULAR BOOTSTRAP3 XML MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript RegExp [^0-9] Expression

RegExp Object Reference JavaScript RegExp Object

Example

Do a global search for the numbers that are NOT 1 to 4 in a string:

var str = "123456789";
var patt1 = /[^1-4]/g;

The marked text below shows where the expression gets a match:

123456789

Try it yourself »


Definition and Usage

The [^0-9] expression is used to find any digit NOT between the brackets.

The digits inside the brackets can be any numbers or span of numbers from 0 to 9.

Tip: Use the [0-9] expression to find any digit between the brackets.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The [^0-9] expression is supported in all major browsers.


Syntax

new RegExp("[^0-9]")

or simply:

/[^0-9]/

Syntax with modifiers

new RegExp("[^0-9]","g")

or simply:

/\[^0-9]/g


More Examples

Example

Do a global search for numbers that are NOT "1" in a string:

var str = "12121212";
var patt1 = /[^1]/g;

The marked text below shows where the expression gets a match:

12121212

Try it yourself »

Example

Do a global search for numbers that are NOT 5 to 8 in a string:

var str = "123456789";
var patt1 = /[^5-8]/g;

The marked text below shows where the expression gets a match:

123456789

Try it yourself »


RegExp Object Reference JavaScript RegExp Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook