File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Possibly a bug in kathy Sierra Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Possibly a bug in kathy Sierra" Watch "Possibly a bug in kathy Sierra" New topic
Author

Possibly a bug in kathy Sierra

Bansal Ankit
Greenhorn

Joined: Dec 03, 2007
Posts: 5
I was going through chapter 6 of kathy sierra. In Objective 3.5, subtopic "Searches Using Quantifiers", it is creating a list of file whose name starts with proj1. the exp it gives is: proj1([^,])* .
I think the expression is wrong as this expression searches for filename containing proj1 not starting with proj1. The pattern should be
,proj1([^,])*
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42273
    
  64
Hello "Ankit Newbee "-

welcome to JavaRanch.

I think it's important to note that any bug would be in Kathy's book, not in Kathy herself

On your way in you may have missed that we have a policy on screen names here at JavaRanch. Basically, it must consist of a first name, a space, and a last name, and not be obviously fictitious. Since yours does not conform with it, please take a moment to change it, which you can do right here.
[ December 03, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
Hi Ankit,
What Kathy has given is correct as far as i think. The expression proj1([^,])* go through the series and will fetch all combinations starting with proj1 (as * is there at end) but as [^,] is there so it wont go further and will stop when it meets a ,, then it will search another pattern like the same.What you have given ,proj1([^,])* will look for all starting with , and this will give you only one pattern.. the very 1st one, that too starting with , and no others as you have given [^,] it will leap over , and find the next one but wont find any with , again. Hope this clears now....
Bansal Ankit
Greenhorn

Joined: Dec 03, 2007
Posts: 5
Hi Dittmer, thanks for your suggestion.

Pranav, I agree with your point that ,proj1([^,])* can't be the solution. But my point is expression proj1([^,])* doesn't specify that filename starts with proj1. For example a filename testproj1 will also be correct based on this expression.
Pranav Bhatt
Ranch Hand

Joined: Mar 20, 2006
Posts: 284
But my point is expression proj1([^,])* doesn't specify that filename starts with proj1. For example a filename testproj1 will also be correct based on this expression.


Ankit,
What you are saying about "testproj1" would have been the result when the pattern you are searching would be *proj1([^,]) as this will search for all words that ends with proj1 in their name like they all could be proj1,testproj1,test1proj1,myproj1... as * means zero or more occurances. Whereas if you put * at the end it will give you all patterns that starts with proj1 and whatever is there after that.. here all searches would feed you with proj1,proj1star,proj1proj2.... Hope you got it..
Bansal Ankit
Greenhorn

Joined: Dec 03, 2007
Posts: 5
Even if you won't put * in the beginning, it will search for that because you are not specifying that p is the first character of the filename. You can try it in eclipse. I don't know how you can specify that filename starts with proj1.
Kelvin Chenhao Lim
Ranch Hand

Joined: Oct 20, 2007
Posts: 513
This is beyond the scope of the SCJP, but you can use the regex (^|,)proj1([^,])* to ensure that the filenames start with "proj1". Note that the caret in (^|,) is not the negation operator in [^,]; rather, this caret denotes "the start of the string". You can correspondingly use $ to denote "the end of the string".

(Of course, you'll now need to clean up the possible leading comma in the returned matches. The best way to avoid this problem is to use a regex capturing group, but that's again outside the scope of the SCJP.)


SCJP 5.0
Bansal Ankit
Greenhorn

Joined: Dec 03, 2007
Posts: 5
Thanks Kelvin.

I was just trying (^|,)proj1([^,])* expression on eclipse and i think for start (|,) is the correct expression because its giving me correct answer .

But for now its enough that these things are out of scope of scjp.
Bansal Ankit
Greenhorn

Joined: Dec 03, 2007
Posts: 5
I am sorry. I got confused in brackets. both [(^|,)] and [|,] are giving me the correct result.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Possibly a bug in kathy Sierra