This?
str = str.replace(/\s/g, '');
Example
var str = '/var/www/site/Brand new document.docx'; document.write( str.replace(/\s/g, '') );
Run code snippetExpand snippet
Update: Based on this question, this:
str = str.replace(/\s+/g, '');
is a better solution. It produces the same result, but it does it faster.
The Regex
\s
is the regex for “whitespace”, and g
is the “global” flag, meaning match ALL \s
(whitespaces).
A great explanation for +
can be found here.
As a side note, you could replace the content between the single quotes to anything you want, so you can replace whitespace with any other string.
Related Posts:
- How to set text color for my d3 chart title?
- Reading local text file into a JavaScript array
- How can I input a single right-to-left paragraph (Hebrew) into an English page/post?
- Automatically decrease font size for long words
- HTML / Javascript in custom field textarea?
- Displaying fractions in text
- printf and _n in this example?
- string translation in functions.php not working
- How to copy/paste web content with photos into my blog
- Custom color does not stick
- Post specific text based on category displayed
- Instructions/Rules Inside Text Area
- Simple Plugin with custom javascript wont work – no console error
- Store unmodified text content in database
- How can I highlight specific pieces of text within a blog post?
- copying text from ms word to wordpress post appears weird [closed]
- Text Stating the Domain Name Appears on Every Page… How to Get Rid of It [closed]
- How to Add a Read-only Textbox With Text in it That Has a Button to Copy it?
- How to replace characters in CPT posts with a newline using Better Search Replace
- Theme Twenty Seventeen – Increasing Font Size for the Home Text
- Theme Twenty Seventeen – Make Margins Smaller So That Text is Wider
- Space between text elements (title and content) in text editor
- How to display text on product catalog
- Change values on several pages
- How can I quickly style a single word with a single keypress (or the most minimum keypresses)?
- Auto Linking Words But Only One Time
- Radio button problem using subtitles and mandatory field check
- Add text to Text Widget using Javascript
- How can I copy value from dropdown once I select it to text area as text?
- Google reCAPTCHA V3.0 not working. “ERROR for site owner: Invalid key type”
- Javascript split regex question
- Find object by id in an array of JavaScript objects
- How fix ‘Failed to load resource: the server responded with a status of 403’?
- Does JavaScript have a method like “range()” to generate a range within the supplied bounds?
- How to make JavaScript execute after page load?
- How do I empty an array in JavaScript?
- JavaScript TypeError: Cannot read property ‘style’ of null
- Usage of the backtick character (`) in JavaScript
- Why is using “for…in” for array iteration a bad idea?
- Parsing a string to a date in JavaScript
- Mouseover & Mouseout w/ Javascript
- Most efficient way to convert an HTMLCollection to an Array
- React Uncaught Error: Target container is not a DOM element [duplicate]
- JavaScript getElementByID() not working
- How to send an email from JavaScript
- align text center with android
- How can I check if an element exists in the visible DOM?
- XMLHttpRequest status 0 (responseText is empty)
- jQuery equivalent of querySelector
- document.getElementById().value doesn’t set the value
- How to remove part of a string?
- How to run a function when the page is loaded?
- Convert normal date to unix timestamp
- Set CSS property in JavaScript?
- how to write javascript code inside php
- Detecting a mobile browser
- jQuery .animate() not working
- How can I capture the right-click event in JavaScript?
- how to add inside a text box?
- Is it possible to enqueue the Youtube API script or does it have to be inline?
- Hide content-box on specific pages (in admin)?
- How do I only load js on the post-new.php and post.php pages in admin?
- Javascript code inside “” in core WordPress files .php
- Get term by slug in Gutenberg
- Passing select control value to block
- Gutenberg RichText
- Convert a complex webpage into WP theme
- Unwanted line break before
- How to integrate my HTML and javascript into my child theme
- Weird links found in wordpress footer
- Save Search System
- dynamic dependent select dropdown
- parts of url disappear when using # inside href=”” [closed]
- GeoMashup plugin: how to customize cluster markers / icons? [closed]
- Noscript not working as it should in wordpress site
- How to deactivate the text, that appears, when you hovering over topbar tabs? [closed]
- Looping over wordpress meta to create “ ‘s?
- Combine multiple getEntityRecords calls
- Install GTM in pure javascript through functions.php
- How to add a panel/box/widget/are/screen to the right side of edit post/page confusion
- Get related product based on subcategory selected from category id with ID 142
- wp_nav_menu not working correctly in my underscores theme
- Javascript not loading after the document ready
- Call current post URL in ajax
- How To Include JavaScript Files Only In Single Posts?
- Meta field bulk editing no longer working in WP 6.0 [closed]
- Ajax call not working in wordpress through a plugin
- how to let users upload their custom cover image
- how to use nimble-API and Display data?
- Create a Dropdown Selector and Redirect for a Custom Taxonomy in WordPress?
- Ajax sometimes work and sometimes just don’t work
- Add “onclick” option to header menu item
- Retrieve Woocommerce Cart Url with javascript/jquery [closed]
- Javascript output now showing in custom widget
- How can I make menu items into two seperate buttons with different functions?
- Cannot access my wordpress website
- Adding javascript to header of MetroMagazine theme
- How can I correctly POST to a WordPress page?
- Load php function with AJAX on modal window
- Get current day using javascript [closed]