File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Matching // * in a file using Matcher and Pattern objects 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 » Java » Beginning Java
Bookmark "Matching // * in a file using Matcher and Pattern objects " Watch "Matching // * in a file using Matcher and Pattern objects " New topic
Author

Matching // * in a file using Matcher and Pattern objects

sunil choudhary
Ranch Hand

Joined: Nov 10, 2000
Posts: 141

Well this is supposed to be regular expression question But I am trying to use java here.
Want to make a java program to read file and from that on cmd line print all lines that contain a // (Commeted code )


with escape characters I Am able to get it working for //


But when I want to make it for String like say "aaas ssssaa aaaaa//aaaa" then it always gives me a false

My trials
-----------
1) Normally an * means anything and everything allowed. If I put * at the end it complains of dangling metacharacter (Anyone has any idea about this) Perhaps perl is more forgiving about trailing *s
2) Even if I put an extra character a at the end still its giving me false for a boolean match Not sure what does it need.



regards
Sunil Choudhary


"Learning is weightless, a treasure you can always carry easily." -Chinese Proverb
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
Try using:

"^.*\\/\\/.*$" or "^.*\\/{2}.*$"

^ denotes the start of the line to be evaluated
. means any character
* means any number of preceeding character
(in this case: any number of any character)
{2} means preceeding (in this case \\/) has to occur exactly twice
$ denotes the end of the line


We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
 
wood burning stoves
 
subject: Matching // * in a file using Matcher and Pattern objects