mohit_king 0 Newbie Poster

Here is the java code to search for multiple patterns in multiple lines...i m not able to go back to the previous pattern using this code...
try tomake an xsl file in the link provided in folder and give the same pattern somewhere in the xsl...and do tell me the changes i have to made

import java.io.*;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class patternMatching10 {

	public static void finder(String s) {
		try {
			final String REGEX = "<!--";
			final String REGEXX = "-->";
			final String REGEXXX = "<";
			final String REGEXXXX = ">";
			String srcDir = s;
			File folder = new File(srcDir);

			File[] listOfFiles = folder.listFiles();
			if (listOfFiles.length > 0) {
				for (int i = 0; i < listOfFiles.length; i++) {

					if (listOfFiles[i].isFile()) {
						String p1 = listOfFiles[i].getName();
						System.out.println("\nPath : " + s + p1);

						BufferedReader br = new BufferedReader(new FileReader(
								srcDir + listOfFiles[i].getName()));

						final String INPUT = "";
						Pattern p = Pattern.compile(REGEX);
						Pattern pp = Pattern.compile(REGEXX);
						Pattern ppp = Pattern.compile(REGEXXX);
						Pattern pppp = Pattern.compile(REGEXXXX);

						Matcher m = p.matcher(INPUT); // get a matcher object
						Matcher mm = pp.matcher(INPUT); // get a matcher object
						Matcher mmm = ppp.matcher(INPUT); // get a matcher
						Matcher mmmm = pppp.matcher(INPUT);
						int count = 0;
						String aLine = null;

						char flag = 'f';
						int mstatus = 0;
						int mmstatus = 0;
						int count1 = 0;
						while ((aLine = br.readLine()) != null) {
							count++;
							System.out.println("main Line No.  is " + count
									+ " is : " + aLine);

							m.reset(aLine);
							while (m.find()) {

								System.out.println("m.start() is  at line "
										+ count + aLine + " start" + m.start());
								mstatus = m.start();
								flag = 't';
								
								while ((aLine = br.readLine()) != null) {
									// System.out.println("count"+count);
									count++;
									// count1++;
									// System.out.println("   line in inner loop is  "+aLine+"   count1 in inner l is   "+count1);

									mmm.reset(aLine);

									while(mmm.find()) {

										if (mmm.start() > mstatus) {

											mmmm.reset(aLine);
											if (mmmm.find()) {
												System.out
														.println("   mmm.start() commented code at line  "
																+ count
																+ "    "
																+ aLine
																+ "   index  "
																+ mmm.start());

											//}

										}}

										else if((mm.find())) {

											System.out
													.println("Comments  end at line : "
															+ count
															+ aLine
															+ "position"
															+ mm.start());
											// System.out.println("m.start()"+m.start());

											//mmstatus = mm.start();

										}
									}}
								}
							}
						//}//}
					} else if (listOfFiles[i].isDirectory()) {

						String directoryToSearch = listOfFiles[i].getName();
						String q = directoryToSearch;
						finder(s + q + '/');

					}// /}
				}
			}
		} catch (Exception e) {
			System.out.println("Exception while reading file: " + e);
		}
	}

	public static void main(String[] args) {
		finder("C:/eclipse_workspace/sampleJavaProject/dir1/");
	}

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.