
- Node.js - Home
- Node.js - Introduction
- Node.js - Environment Setup
- Node.js - First Application
- Node.js - REPL Terminal
- Node.js - Command Line Options
- Node.js - Package Manager (NPM)
- Node.js - Callbacks Concept
- Node.js - Upload Files
- Node.js - Send an Email
- Node.js - Events
- Node.js - Event Loop
- Node.js - Event Emitter
- Node.js - Debugger
- Node.js - Global Objects
- Node.js - Console
- Node.js - Process
- Node.js - Scaling Application
- Node.js - Packaging
- Node.js - Express Framework
- Node.js - RESTFul API
- Node.js - Buffers
- Node.js - Streams
- Node.js - File System
- Node.js MySQL
- Node.js - MySQL Get Started
- Node.js - MySQL Create Database
- Node.js - MySQL Create Table
- Node.js - MySQL Insert Into
- Node.js - MySQL Select From
- Node.js - MySQL Where
- Node.js - MySQL Order By
- Node.js - MySQL Delete
- Node.js - MySQL Update
- Node.js - MySQL Join
- Node.js MongoDB
- Node.js - MongoDB Get Started
- Node.js - MongoDB Create Database
- Node.js - MongoDB Create Collection
- Node.js - MongoDB Insert
- Node.js - MongoDB Find
- Node.js - MongoDB Query
- Node.js - MongoDB Sort
- Node.js - MongoDB Delete
- Node.js - MongoDB Update
- Node.js - MongoDB Limit
- Node.js - MongoDB Join
- Node.js Modules
- Node.js - Modules
- Node.js - Built-in Modules
- Node.js - Utility Modules
- Node.js - Web Module
Node.js - doesNotMatch() Function
The Node.js assert.doesNotMatch() function will expect the string which is passed as a parameter not to match with the regex (regular expression) which will be passed in the second parameter to the function.
This is an inbuilt function of the assert module of Node.js.
Syntax
Following is the syntax of Node.js assert.doesNotMatch() function −
assert.doesNotMatch(string, regexp[, message]);
Parameters
This function accepts three parameters. The same are described below.
String − (required) This parameter will only accept if the input is a string else it will throw an AssertionError to the output.
Regexp − (required) In this parameter, we need to pass a regular expression that should not match the string. If both the inputs (string & regexp) are the same it will throw an AssertionError to the output.
Message − (optional) String or Error type can be passed as an input into this parameter.
Return Value
This method will throw an AssertionError to the output when both the inputs (string & regexp) are the same.
Example
In the example below, we passed both string and regex values to the Node.js assert.doesNotMatch() function along with the message.
const assert = require('assert'); var str = 'Tutorialspoint'; var reg = /E-learning platform/; assert.doesNotMatch(str, reg, 'Both are not matching');
Output
When we compile and run the code, the function will not throw any AssertionError to the output as both string and regex are not the same.
// Returns nothing
Example
In the example below, we passed both String and regex values to the Node.js assert.doesNotMatch() function along with the message. But the value we are passing to the string is an integer.
const assert = require('assert'); var str = 96864; var reg = /E-learning platform/; assert.doesNotMatch(str, reg, 'Integer is passes instead of string');
Output
When we compile and run the code, the function will throw AssertionError along with the message to the output because the String input value must be string only.
/home/cg/root/639c2bf348ea8/main.js:6 assert.doesNotMatch(str, reg, 'Integer is passes instead of string'); ^ TypeError: assert.doesNotMatch is not a function at Object.<anonymous> (/home/cg/root/639c2bf348ea8/main.js:6:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Example
In the example below, we passed String and regexp to the Node.js assert.doesNotMatch() function to compare. But we haven't passed any text into the message parameter.
const assert = require('assert'); var str = 436; var reg = /Number/; assert.doesNotMatch(str, reg);
Output
When we compile and run the code, the function will assign a default error message.
/home/cg/root/639c2bf348ea8/main.js:6 assert.doesNotMatch(str, reg); ^ TypeError: assert.doesNotMatch is not a function at Object.<anonymous> (/home/cg/root/639c2bf348ea8/main.js:6:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12)at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Example
In the example below, we passed both String and regex values to the Node.js assert.doesNotMatch() function along with the message.
const assert = require('assert'); var str = 'Bahubali'; var reg = /Bahubali/; assert.doesNotMatch(str, reg, 'Both the values are exactly same');
Output
When we compile and run the code, the function will throw an AssertionError to the output as both string and regex are the same.
/home/cg/root/639c2bf348ea8/main.js:6 assert.doesNotMatch(str, reg, 'Both the values are exactly same'); ^ TypeError: assert.doesNotMatch is not a function at Object.<anonymous> (/home/cg/root/639c2bf348ea8/main.js:6:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
Example
In the example below, we passed both String and regex values to the Node.js assert.doesNotMatch() function along with the message.
const assert = require('assert'); var str = 'Good to see you back officer'; var reg = /see/; assert.doesNotMatch(str, reg, 'Both the values are partially same');
Output
When we compile and run the code, the function will throw an AssertionError to the output as both string and regex are partially the same.
/home/cg/root/639c2bf348ea8/main.js:6 assert.doesNotMatch(str, reg, 'Both the values are partially same'); ^ TypeError: assert.doesNotMatch is not a function at Object.<anonymous> (/home/cg/root/639c2bf348ea8/main.js:6:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)