Code that i tried:
import java.io.*;
import java.util.regex.*;
public class All {
public static void main(String[] args) {
String input = "IT&&faculty.*";
try {
FileInputStream fstream = new FileInputStream("uu.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
if (Pattern.matches(input, strLine)) {
Pattern p = Pattern.compile("'(.*?)'");
Matcher m = p.matcher(strLine);
while (m.find()) {
String b = m.group(1);
String c = b.toString() + ".*";
System.out.println(b);
if (Pattern.matches(c, strLine)) {
Pattern pat = Pattern.compile("<(.*?)>");
Matcher mat = pat.matcher(strLine);
while (mat.find()) {
System.out.println(m.group(1));
}
} else {
System.out.println("Not found");
}
}
}
}
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
}
The contents of my text file are: \ indicates it is a newline
Input file:
IT&&faculty('Mousum handique'|'Abhijit biswas'|'Arnab paul'|'Bhagaban swain')
Mousum handique(designation|address|phone number|'IT Assistant professor'|<AUS staff quaters>|#5566778899#)
Abhijit biswas(designation|address|phone number|'IT Assistant professor'|<AUW staff quaters>|#5566778891#)
Arnab paul(designation|address|phone number|'IT Assistant professor'|<AUE staff quaters>|#5566778890#)
Bhagaban swain(designation|address|phone number|'IT Assistant professor'|<AUW staff quarters>|#5566778892#)
it gives result -
Mousum handique
Not found
Abhijit Biswas
Not found
Arnab Paul
Not found
Bhagaban swain
Not found
whereas the results i want is:
Mousum handique
AUS staff quaters
Abhijit Biswas
AUW staff quaters
Arnab Paul
AUE staff quaters
Bhagaban swain
AUW staff quaters
That is i want after 1st match when it gets Mousum handique from the file it should again search the file and where it gets line like Mousum handique it should print whatever within <> for that corresponding line. Please refer data of my text file to understand my question. Sorry if my question seems stupid but i m trying it a lot!