- 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
JavaScript regex - How to replace special characters?
To replace special characters, use replace() in JavaScript.
The syntax is as follows −
anyVariableName.replace(/(^\anySymbol)|,/g, '');
Example
Following is the code −
var values = '&677,431,444,98777'; var result=values.replace(/(^\&)|,/g, ''); console.log(result);
To run the above program, you need to use the below command −
node fileName.js.
Here, my file name is demo319.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo319.js 67743144498777
- Related Articles
- How to replace all the special characters following another character – JavaScript?
- How to escape all special characters for regex in Python?
- MySQL query to replace special characters from column value
- Replace commas with JavaScript Regex?
- How can we separate the special characters in JavaScript?
- Dynamically replace data based on matched RegEx - JavaScript?
- How to replace characters except last with a mask character in JavaScript?
- How to match word characters using Java RegEx?
- How to match the regex meta characters in java as literal characters.
- How to use special characters in Python Regular Expression?
- How to use Unicode and Special Characters in Tkinter?
- How to count special characters in an R vector?
- Special Characters in HTML
- How to replace characters on String in Java?
- How to Replace characters in a Golang string?

Advertisements