Haloor Haloor - 2 years ago 114
Javascript Question

How to split a string by uppercase and lowercase in JavaScript?

Is it possible to split Strings in JavaScript by case such that the following string below (myString) would be converted into the array (myArray) below:

var myString = "HOWtoDOthis";
var myArray = ["HOW", "to", "DO", "this"];

I have tried the regex below, but it only splits for camelCase:


Answer Source

([A-Z]+|[a-z]+). Match all upper case, or all lower case multiple times in capturing groups. Give this a try here: https://regex101.com/r/bC8gO3/1

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download