- 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
Separate a string with a special character sequence into a pair of substrings in JavaScript?
Let’s say we have the following string with special character sequence −
var fullName=" John <----> Smith ";
To separate the above string into substring, use regex and then split(). The syntax is as follows −
var anyVariableName=(/\s*<---->\s*/g); var anyVariableName=yourVariableName.trim().split(yourVariableName);
Following is the complete JavaScript code −
Example
var fullName=" John <----> Smith "; console.log("The Value="+fullName); var regularExpression=(/\s*<---->\s*/g); var seprateName=fullName.trim().split(regularExpression); console.log(seprateName);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo39.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo39.js The Value= John <----> Smith [ 'John', 'Smith' ]
- Related Articles
- Segregating a string into substrings - JavaScript
- How to build a string with no repeating character n separate list of characters? in JavaScript
- C# Program to replace a special character from a String
- Get all substrings of a string in JavaScript recursively
- MySQL query to display a substring before a special character in a string
- PHP program to check if a string has a special character
- Find word character in a string with JavaScript RegExp?
- Is the string a combination of repeated substrings in JavaScript
- How to remove partial string after a special character in R?
- Finding count of special characters in a string in JavaScript
- Find non-word character in a string with JavaScript RegExp
- Replacing all special characters with their ASCII value in a string - JavaScript
- How do we split a string on a fixed character sequence in java?
- How to split a long string into a vector of substrings of equal sizes in R?
- Program to check if a string contains any special character in C

Advertisements