• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sunil choudhary
Ranch Hand
Posts: 144
Java Redhat Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Scheepers de Bruin
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic