This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regex Doubt

 
zhy guo
Greenhorn
Posts: 3
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic