- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to replace all the special characters following another character – JavaScript?
Let’s say the following is our string with special characters −
var sentence = '<My<Name<is<John<Doe';
We are replacing the special character and setting a space with it using replace() along with regex.
Example
Following is the code −
var sentence = '<My<Name<is<John<Doe'; var regularExpresion = /<(?!\s)/g; var result = sentence.replace(regularExpresion, "< "); console.log(result);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo271.js
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo271.js < My< Name< is< John< Doe
- Related Articles
- JavaScript regex - How to replace special characters?
- How to replace characters except last with a mask character in JavaScript?
- Python program to replace all Characters of a List except the given character
- MySQL query to replace special characters from column value
- C# Program to replace a special character from a String
- How to escape all special characters for regex in Python?
- How can we separate the special characters in JavaScript?
- Write a Regular Expression to remove all special characters from a JavaScript String?
- Java Program to replace one specific character with another
- Replacing all special characters with their ASCII value in a string - JavaScript
- MySQL: How can I find a value with special character and replace with NULL?
- Program to replace all digits with characters using Python
- Java Program to replace all occurrences of a given character with new character
- Replace all characters in a string except the ones that exist in an array JavaScript
- How to remove all special characters, punctuation and spaces from a string in Python?

Advertisements