Sometimes, we want to split JavaScript string on upper case characters.
In this article, we’ll look at how to split JavaScript string on upper case characters.
How to split JavaScript string on upper case characters?
To split JavaScript string on upper case characters, we can call the string split
method with a regex.
For instance, we write
const a = "ThisIsTheStringToSplit".split(/(?=[A-Z])/);
to call split
with /(?=[A-Z])/
to split the string on upper case characters.
We use ?=
to keep the whole word intact after splitting.
split
returns an array with the split strings.
Conclusion
To split JavaScript string on upper case characters, we can call the string split
method with a regex.