tags:

views:

35

answers:

2

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.

+1  A: 

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:

Mark Byers
+3  A: 

In Perl:

$string =~ s/([\w']+)/\u\L$1/g;

(taken from the Perl FAQ)

gawi