Is it possible to convert an all-uppercase string into a string where only the first letter of each word is in upper case using regular expressions?
THIS IS A SAMPLE STRING
开发者_运维知识库--->
This Is A Sample String
At first I thought this would be an easy task, but now I don't even know how to start or even if it is possible.
In Perl:
$string =~ s/([\w']+)/\u\L$1/g;
(taken from the Perl FAQ)
No, in most languages you can't use regular expressions to do that. An exception to this is Perl which has a particularly powerful "regular" expression syntax.
You will probably find that your language has a library function that can do it. Look for something like s.titlecase()
.
Related:
- Format string to title case
精彩评论