You need the put the characters you wish to split on in a character class, which tells the regular expression engine “any of these characters is a match”. For your purposes, this would look like:
date.split(/[.,\/ -]/)
Although dashes have special meaning in character classes as a range specifier (ie [a-z]
means the same as [abcdefghijklmnopqrstuvwxyz]
), if you put it as the last thing in the class it is taken to mean a literal dash and does not need to be escaped.
To explain why your pattern didn’t work, /-./
tells the regular expression engine to match a literal dash character followed by any character (dots are wildcard characters in regular expressions). With “02-25-2010”, it would split each time “-2” is encountered, because the dash matches and the dot matches “2”.
Related Posts:
- Split string into array
- 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
- What is causing the error `string.split is not a function`?
- What is causing the error `string.split is not a function`?
- Converting any string into camel case
- I want to remove double quotes from a String
- Regular expression for removing whitespaces
- 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
- Sort array of objects by string property value
- Chrome sendrequest error: TypeError: Converting circular structure to JSON
- How to deal with floating point number precision in JavaScript?
- What’s a maximum call stack size exceeded error and how to fix it?
- NPM ELIFECYCLE error – using node server.js command
- Is there a link to the “latest” jQuery library on Google APIs?
- How do I correctly clone a JavaScript object?
- Get class name using jQuery
- How to clear the canvas for redrawing
- No value accessor for form control
- React eslint error missing in props validation
- How to specify multiple conditions in an if statement in javascript
- Mongoose – What does the exec function do?
- Developing an ad with MRAID.js
- ReferenceError: Invalid left-hand side in assignment
- illegal use of break statement; javascript
- Open URL in same window and in same tab
- ReferenceError: document is not defined (in plain JavaScript)
- JavaScript innerHTML not updating element
- Palindrome check in Javascript
- Console is throwing Unterminated JSX contents error
- Console.log not working at all
- How to move an element after another element using JS or jquery?
- Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside StrictMode
- How to use Javascript to read local text file and read line by line?
- Why is the jquery script not working?
- JQuery Datatables : Cannot read property ‘aDataSort’ of undefined
- includes() not working in all browsers
- getElementsByAttribute() is not a function
- Javascript onload not working
- How to parse float with two decimal places in javascript?
- Checking for duplicate strings in JavaScript array
- How to get current date in jQuery?
- Print the contents of a DIV
- Remove all special characters except space from a string using JavaScript
- What does the .subscribe() function do?
- is there something like isset of php in javascript/jQuery?
- jQuery – Dynamically Create Button and Attach Event Handler
- Highlight a word with jQuery
- How to reload page every 5 seconds?
- How do I handle newlines in JSON?
- Update style of a component onScroll in React.js
- Fire oninput event with jQuery
- Reset Undo on the tinymce editor
- Detecting WordPress Customizer Panel
- Customizer – instantiating settings and controls via javascript
- How do I enqueue(or delay loading of) tags in individual page posts?
- JavaScript in page doesn’t open new window [closed]
- Dynamically insert values in a WordPress SelectControl Options field
- can a buttongroup have a label?
- Preloader for a WordPress Site
- Trying to integrate Zoho Campaign Form [closed]
- InnerBlocks restricting does not work on nested blocks
- How to execute Javascript on a WordPress page?
- Removing auto versioning of JS and loading to header
- Gutenberg select excerpt, use generated excerpt or use more block excerpt
- Unable To Call Javascript With Enqueue
- How to integrate a JS fiddle?
- Hovercards and other hover over image functions don’t work anymore!
- How WP does Mortgage affordability calculation
- Putting custom html/js page into Elementor as it’s own block
- java console error about touch navigation
- Update block once an API request returns with a value
- How to improve WP-Rest atrocious response time?
- How do I add a class to Customizer preview based on class of Customizer control? (Customizer Javascript API)
- Open image gallery on link click
- WordPress 4.2 mce-views migration guide?
- Loaded JavaScript file not showing [duplicate]
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?