Replace character in nodejs for ejs template
#nodejs replace all character in string #nodejs replace all special characters #replace special #characters in string nodejs #replace all in nodejs #ejs template in node js #replace in node
A string of characters called a regular expression.With help RegExp creates a search pattern and we can remove character ,number and special character.In our code we can transform the string new format .We can observe that regular expression can be a simple pattern or just a single character in below example :-
var str=" <h> Hello, World! </h> "
console.log(str.replace(/"/g, `'`))
We are understand that this era is depend on technology and we have most popular language that is NODE JS . Node js is generated dynamic page content for web application.
Here we discuss about a library of node js that is EJS.
For configure EJS in Node js you need to use following :
var express = require('express');
app.set('view engine', 'ejs')
One of the most well-liked JavaScript template engines is EJS.
The full form of ejs Embedded JavaScript Templating). As the name implies, it enables us to include JavaScript code in a template language that produces HTML.
Here we are replacing a special character from String except small letter, capital letter and number.
var str=" <h> Hello, World! </h> "
console.log(str.replace(/[^a-zA-Z0-9]/g, ' '))
Here we are replacing a special character from String except small letter, capital letter ,number and < , > , / . For this below is example :
var str=" <h> Hello, World! </h> "
console.log(str.replace(/[^a-zA-Z0-9<>//]/g, ' '))
In this article, you have understand the difference between multiple character and single character Regular Expression.
We can use a function replace in our example .So it is pretty simple to undertand logic on this topic.