File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex Doubt

 
zhy guo
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain the output of the codes?
source: "a23kb28c9b"
pattern: ^[abc]
the output:0 a

-------------
the codes :
public static void main(String[] args){
if (args.length > 1) {
Pattern p = Pattern.compile(args[0]);
Matcher m = p.matcher(args[1]);

while(m.find()){
System.out.println(m.start() + " " +m.group());
}
}
}
 
Pranav Bhatt
Ranch Hand
Posts: 284
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As you have used negation (^) outside the box []. It will serve as boundary condition. So this will search any string that starts with either a or b or c.
Check more out here. Boundary Matches
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic