File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes pattern matching doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "pattern matching doubt" Watch "pattern matching doubt" New topic

pattern matching doubt

akila sekaran
Ranch Hand

Joined: Jun 12, 2012
Posts: 48
i used the following string to match files that have .cpp or c++ or cc extension. but it gives error. I think some problem is there is the syntax. But no idea what it would be.

Anayonkar Shivalkar

Joined: Dec 08, 2010
Posts: 1545

akila sekaran wrote:but it gives error

Please, TellTheDetails. What is the error? (by 'error', do you mean compilation error? in that case, a single line of code won't help us to figure out the actual problem)

Also, during pattern matching, (at least I) follow the process of 'starting with small' - e.g. firstly, make the code working with '.' in the string, then make it working with .cpp, and then go for multiple extensions.

I hope this helps.

Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Winston Gutkowski

Joined: Mar 17, 2011
Posts: 8956

Akila, I really think you need to read the HowToAskQuestionsOnJavaRanch (←click) page.

Just providing a few lines of code and firing off vague questions like "I have a doubt about..." or "I think there's some problem, but..." gives the impression that you:
(a) Haven't bothered to read the tutorials (or the requisite material for your class).
(b) Haven't made an effort to at least try some solutions yourself.
(c) Want someone else to do your work for you.

Now all of the above may be false, but you need to learn to ask precise questions to avoid giving that impression.
My advice: After you've read our page, have a look at this one and this one. The first contains several excellent tips on how to formulate questions properly, particularly ones that involve programming code, and the second is a great general guide to asking question on sites like ours.

Remember: It's the policy of this site not to just "hand out answers".



Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here
Ashwin Soni

Joined: Jun 22, 2012
Posts: 18

According to 1 line of code you have given it will give "illegal escape character" error at compile time. And this error occurs if you attempt to use backlash before a wrong character where it shouldn't be.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46429
You need to replace the single \ with \\ before the dot.
I agree. Here's the link:
subject: pattern matching doubt
It's not a secret anymore!