I’m currentl using
thing.replace(/([a-z])([A-Z])/g, "$1 $2"); to split a string on capitals like so.
HereAreSomeWords ====== Here Are Some Words
SomeMoreStuff ====== Some More Stuff
I’d like to update the regex so that it will split on groups of numbers as well. So the desired output would be:
123SomeWords ======== 123 Some Words
Some1Words ======= Some 1 Words
Some1234Words ======= Some 1234 Words
Does anyone have any thoughts on how to do this?
Try the pattern:
and replace it with this:
Here’s a demo:
which prints:
as you can see on Ideone: http://ideone.com/KE64z
edit
Perhaps a more intuitive way would be to globally match the parts you’re interested in (either numbers:
\d+, or capitalized words:[A-Z][a-z]*) andjoin(' ')these together:which would result in the same output.
Note that my examples only take ascii letters in account: words like
caféwould not work because of theé!