This can be done in a single String#replace
call:
var repl = str.replace(/^\s+|\s+$|\s+(?=\s)/g, ""); // gives: "tushar is a good boy"
Related Posts:
- Javascript split regex question
- What is a good regular expression to match a URL? [duplicate]
- What is a good regular expression to match a URL? [duplicate]
- Is there a difference between /\s/g and /\s+/g?
- RegEx Ignore Case
- JavaScript replace/regex
- Regex for password must contain at least eight characters, at least one number and both lower and uppercase letters and special characters
- Escaping Discord subset of markdown
- How to test valid UUID/GUID?
- Regular expression : match either of two conditions?
- RegExp in TypeScript
- Converting any string into camel case
- I want to remove double quotes from a String
- Javascript Regular Expression Remove Spaces
- How can I extract a number from a string in JavaScript?
- Remove not alphanumeric characters from string
- Extract hostname name from string
- Difference between ?:, ?! and ?=
- Remove all special characters with RegExp
- How do you use a variable in a regular expression?
- How to count string occurrence in string?
- Regular Expression to reformat a US phone number in Javascript
- Jquery Value match Regex
- RegEx: How can I match all numbers greater than 49?
- Regular expression to validate US phone numbers?
- javascript includes() case insensitive
- RegEx for Javascript to allow only alphanumeric
- Check user logged in with JS
- How to make a word underline in Markdown
- Creating multiline strings in JavaScript
- Babel 6 regeneratorRuntime is not defined
- What is JSONP, and why was it created?
- React – uncaught TypeError: Cannot read property ‘setState’ of undefined
- SyntaxError: Unexpected token o in JSON at position 1
- Remove duplicate values from JS array
- Add swipe left/right to web page, but use default swipe up/down
- Check if checkbox is checked with jQuery
- What does “res.render” do, and what does the html file look like?
- How to Create simple drag and Drop in angularjs
- stop all instances of node.js server
- Working with $scope.$emit and $scope.$on
- Using Node.js require vs. ES6 import/export
- How can jQuery deferred be used?
- Uncaught TypeError : cannot read property ‘replace’ of undefined In Grid
- Disable/enable an input with jQuery?
- How to refresh a Page using react-route Link
- ChangeDate – Date Picker Bootstrap
- Is there a sleep function in JavaScript?
- How to set the id attribute of a HTML element dynamically with angularjs (1.x)?
- Using $setValidity inside a Controller
- Combination of async function + await + setTimeout
- How to go from one page to another page using javascript?
- How to update array value javascript?
- JSON.parse() not working
- Call python function from JS
- How to add onload event to a div element
- Access Control Origin Header error using Axios
- Structs in Javascript
- Refused to execute script, strict MIME type checking is enabled?
- Error: [ng:areq] from angular controller
- getElementsByAttribute() is not a function
- Javascript onload not working
- setInterval with loop time
- JavaScript by reference vs. by value
- navigator.geolocation.getCurrentPosition sometimes works sometimes doesn’t
- Expected ‘this’ to be used by class method
- Strip HTML from Text JavaScript
- How to disable auto-start of “Node.js: Server-side JavaScript” when using Adobe Dreamweaver?
- How should I initialize jQuery?
- How to reload page every 5 seconds?
- WordPress Bootstrap Handburger Menu Wont Open
- How to disable hoverIntent in WordPress 3.3 admin
- Animations are not being triggered on Scroll
- Preserve Javascript Through Customizer Preview Navigation
- Prevent escaping javascript in visual editor
- JavaScript in WordPress Customizer
- @wordpress/components Button variants not styled
- How to use div -ids in url to jump to specific post…Is trailing slash the culprit?
- Button insert link on front wp_editor not working
- How Can I Add OnClick Event To A Specific WordPress Menu Link
- What’s the most efficient way to include this javascript in only a single post?
- Adding a Javascript slideshow to the home page
- Screen Resolution Detect
- How to add customizer control via javascript ( wp.customizer.control.add )
- Automatically Add Defer or ASYNC to all JS files (no matter where they are located)
- How to generate the COOKIEHASH from JavaScript
- Gutenberg select excerpt, use generated excerpt or use more block excerpt
- find out reason of “Updating failed” in Post-editor
- Unable To Call Javascript With Enqueue
- Getting a variable inside foreach from PHP to JS after localization
- How to integrate a JS fiddle?
- Problem after upgrade to 3.6.1
- Hovercards and other hover over image functions don’t work anymore!
- Load JavaScript on specific page with @wordpress compiler
- When adding google tag script in website, functionality not working
- How to improve WP-Rest atrocious response time?
- How should I identify the inline javascript that is the dependent of a wp_enqueue_script?
- WP REST API – “rest_user_cannot_view” ONLY on specific users
- Uncaught ReferenceError: tippy is not defined
- How to add a new attribute to core wp block editor without npm?