using regular expression for searching phrase in the file
So...
Task:
I have some phrase. the phrase contains 2 words. Phrase is devided into two words with next symbols:
[\s]*
How can i find the phrase using regular expression?
This code doesn't work on a file:
// file: Main.java
class
Main {
}
program
Pattern pattern = Pattern.compile("class[\\s]+Main");
BufferedReader input = new BufferedReader ( new FileReader( "Main.java" ) );
int id = 0;
for ( String line = input.readLine(); line != null; line = input.readLine() )
{
++id;
Matcher matcher = pattern.matcher( line );
if ( matcher.find() )
{
System.out.println("number = " + id );
System.out.println("start = " + matcher.start() );
System.out.println("end = " + matcher.end() );
System.out.println( );
}
}
input.close();