
- 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 to write a Regular Expression in JavaScript to remove spaces?
To remove spaces in JavaScript, you can try to run the following regular expression. It removes the spaces from a string −
Example
<html> <head> <script> var str = "Welcome to Tutorialspoint"; document.write(str); //Removing Spaces document.write("<br>"+str.replace(/\s/g, '')); </script> </head> <body> </body> </html>
Output
- Related Articles
- How to remove white spaces using Java Regular Expression (RegEx)
- Write a Regular Expression to remove all special characters from a JavaScript String?
- How to write JavaScript Regular Expression for multiple matches?
- How to strip spaces/tabs/newlines using Python regular expression?
- How to define a Regular Expression in JavaScript?
- How to write a Python regular expression to use re.findall()?
- How to write a Python Regular Expression to validate numbers?
- How to clone a given regular expression in JavaScript?
- How to test and execute a regular expression in JavaScript?
- How to write Python regular expression to check alphanumeric characters?
- How to remove tabs and newlines using Python regular expression?
- How to write a Python regular expression to get numbers except decimal?
- How to write a Python regular expression to match multiple words anywhere?
- How to write a regular expression to match either a or b in Python?
- How to write Python Regular Expression find repeating digits in a number?

Advertisements