This question is based on the example given in Sun Certified Programmer guide by Kathy . Assume I have a String"abc,def,proj3.txt,proj1sched.pdf,proj1,proj2,proj1.java,project,projectile,projection,projection.txt", which basically denotes the list of all available files and folders. I want to retrieve "Only" folders. That is my outcome should be abc def proj1 proj2 project projectile projection
I tried to workout on this problem, taking the entire string at a time. But I could not find any solution for that.Hence I tokenized the string dividing them into individual tokens and checked whether there is '.' in each and every token thus making it disqualified to be called as a folder. This logic worked, but I know this is not what I was looking for. How do I list out only folders by taking the entire string at a time? What is the pattern I can use here. Thanks in advance.
Thanks Henry. The solution is really awesome, though I'm not really comfortable at the pattern .
But keep in mind that a long solution that you understand is better than a short solution that you don't.
This is very much true in my case. Would you mind suggesting any resource to learn more about these regex as Kathy's book on SCJP is more exam oriented and most of the expression you used is not covered in the book.
Originally posted by Chandra Kota: This is very much true in my case. Would you mind suggesting any resource to learn more about these regex as Kathy's book on SCJP is more exam oriented and most of the expression you used is not covered in the book.
Unfortunately, I learned via years of programming with sed, awk, TCL and of course, Perl -- the Perl online docs are actually very good.
I have never read a Java book on Regex, but one of Javaranch's own Sheriffs wrote one...