Home > Back-end >  Code written in Java, the use of regular expressions, please explain
Code written in Java, the use of regular expressions, please explain

Time:10-10

Input an arbitrary string, will be one of the digital respectively output (implementation) using regular expressions,
For example: the input string to "a12b3cc5de67a", the output 12 3 5, 67,

The string go wuhan "go China" converted to capitalize the first letter of each word such as "go wuhan go Chian" (hint: use regular expressions of grouping implementation).

CodePudding user response:

For example
The Matcher m=Pattern.com running (" (\ \ d +) "). The Matcher (" a12b3cc5de67a ");
While (m. ind ()) {
System. The out. Printf (" % s ", m.g roug (1));
}

M=Pattern.com running (" (\ \ w) "). The matcher (" go wuhan go China ");
While (m. ind ()) {
String s=Character. ToUpperCase (m.g roup (1). The charAt (0)) + m.g roup (1) the substring (1);
System. The out. Printf (" % s ", s);
}

  • Related