
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How can we separate the special characters in JavaScript?
To separate the special character, use the concept of match() with Regular Expression. The syntax is as follows −
yourStringName.flatMap(anyVariableName => yourVariableName.match(/\w+|\W+/g));
Let’s say, the following is our array with special characters in between values −
var allNames = ['John-Smith', 'David', 'Carol%Taylor'];
Let’s now see how to separate text with special characters. Following is the code −
Example
var allNames = ['John-Smith', 'David', 'Carol%Taylor']; var output = allNames.flatMap(obj => obj.match(/\w+|\W+/g)); console.log(output);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo32.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo32.js [ 'John', '-', 'Smith', 'David', 'Carol', '%', 'Taylor' ]
- Related Articles
- How can we escape special characters in MySQL statement?
- How to separate strings in R that are joined with special characters?
- JavaScript regex - How to replace special characters?
- How to convert special characters to HTML in Javascript?
- How can we separate colloidal mixtures?
- How to replace all the special characters following another character – JavaScript?
- How can we separate types of dal?
- How can we separate oil from water?
- How can we separate salt from the salt solution?
- What is the role of special characters in JavaScript Regular Expressions?
- How can we separate wheat and red chillies?
- Special Characters in HTML
- Formatting a string to separate identical characters in JavaScript
- Finding count of special characters in a string in JavaScript
- How can I escape HTML special chars in JavaScript?

Advertisements