This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Regex Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex Doubt " Watch "Regex Doubt " New topic
Author

Regex Doubt

zhy guo
Greenhorn

Joined: Aug 21, 2005
Posts: 3
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

Joined: Mar 20, 2006
Posts: 284
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.
 
subject: Regex Doubt