REGEX: Appending Single Space between Capitals in Javascript
I got some idea from a C# related thread, but I need it in Javascript. I am try all sorts of things, it doesn't seem to work.
name.replace(/[A-Z]/g, / $&/);
What I am trying to do is make:
FirstN开发者_运维知识库ame
with spaces:
First Name
But what I get is:
/ F/irst/ N/ame
Any ideas would be much appreciated.
"FirstName".replace(/([a-z])([A-Z])/g, '$1 $2')
That results in
First Name
Without a leading space.
s.replace(/[A-Z]/g, ' $&')
The second parameter need not be a regex, but a string instead.
Remove the /
from the replace section. Some languages need them, some don't.
精彩评论