File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Regex Doubt " Watch "Regex Doubt " New topic

Regex Doubt

zhy guo

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]);

System.out.println(m.start() + " ";
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
wood burning stoves
subject: Regex Doubt
It's not a secret anymore!