Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

kb p. 498

 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(question 1 of chapter 6 test)

import java.util.regex.*;
class Regex2 {
public static void main(String args[]) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);
boolean b = false;
while (b = m.find()) {
System.out.print(m.start() + m.group());
}
}
}

and command line: java Regex2 "\d*" ab34ef

Answer gives result of 01234456 (option E).

I get 0123445. How can m.start() return 6 when the source only has 6 elements?

Ken Truitt
 
sridhar row
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic