Results 1 to 5 of 5
Thread: Using Regex for Capitalization
- 02-14-2010, 09:19 PM #1
Using Regex for Capitalization
what's wrong with this? It won't capitalize the first letter of every word. Any help appreciated.Java Code:public class Grammar { private static String capitalize(String str) { return str.toLowerCase().replaceAll("(^|\\s)([a-z])","$1$2".toUpperCase()); } public static void main(String[] args) { System.out.println(capitalize("hi dude")); } }"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
-
It calls toUpperCase on the String literal "$1$2", which does nothing, and then uses that result as the replacement String.
- 02-14-2010, 10:33 PM #3
is it possible for me to evaluate $1$2 first?
p.s: I need to do this without using loops, recursive, or anything that is not regex.Last edited by Lil_Aziz1; 02-14-2010 at 10:38 PM.
"Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
-
- 02-15-2010, 12:23 AM #5
Similar Threads
-
Interpretation of regex?
By Ms.Ranjan in forum New To JavaReplies: 2Last Post: 04-23-2009, 06:37 PM -
Multiline Regex
By zriggle in forum New To JavaReplies: 1Last Post: 02-26-2009, 04:49 AM -
Some help with regex and loop
By moaxjlou in forum New To JavaReplies: 21Last Post: 11-02-2008, 10:24 PM -
[SOLVED] More RegEx help
By JT4NK3D in forum New To JavaReplies: 2Last Post: 05-23-2008, 04:07 AM -
Regex Quantifiers Example
By Java Tip in forum Java TipReplies: 0Last Post: 01-10-2008, 10:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks