Hi Ranchers,
I have a file called file1.txt with following contents:
1 prabhatpankaj
2
3 select hello.pankaj("prabhat");
4 select hello.pankaj(prabhat);
5 select pack.prabhat ()
6 "select * From prabhat"
7 "select * From prabhat "
8 Prabhat
9 select hello.pankaj( prabhat );
10 select hello.pankajPrabhat;
here i have to search
word prabhat (case-insensitive). the valid ocuurences are at line 3,4,5,6,7,
8,9 but at line 1 and 10 it is not valid.
i have written a small
java code for that like
public static void searchMethod(){
File file = new file (" C:\\Documents and Settings\\prabhat_kumar04\\Desktop\\Testing\\file1.txt");
FileReader fr =new FileReader(file);
BufferedReader br=new BufferedReader(fr);
//Setting the linenumber for searching.
int lineNumber=1;
String data= br.readLine();
while(data!=null)
{
data=data.toUpperCase();
Pattern p = Pattern.compile("[\\W]PRABHAT[\\W]");
Matcher matcher=p.matcher(data);
while(matcher.find()){
System.out.println(" prabhat is at line number :"+lineNumber);
}
// increment the line number
lineNumber++;
// read the next line of file and store into String "data".
data=br.readLine();
}
}
the problem is when i am calling this method it is not showing the line 8 as valid occurence.
Moreover if we write as
Pattern p = Pattern.compile("PRABHAT[\\W]");then it will take as line 8 and 10 bot valid one,whereas line 10 should be invalid.
Suggest the pattern that would fulfil the requirement.
With thanks in advance'
Prabhat
[ April 28, 2008: Message edited by: David O'Meara ]