• Post Reply Bookmark Topic Watch Topic
  • New Topic

regex  RSS feed

 
art older
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
given:
import java.util.regex.*;
class A {
public static void main (String[] args) {
boolean b = false;
String s = "\\d*";
String t = "ab34ef";
Pattern p = Pattern.compile(s);
Matcher m = p.matcher(t);
while (b = m.find() {
System.out.println(m.start() + m.group());
}
}

The output from this is 01234456.
How does the index value of 6 ever get printed? Shouldn't
5 be the largest number possible for the m.start() value?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Javaranch FAQ is your friend: Could someone explain the Regex2 class from K&B's Java 5 Study Guide?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!