Hi folks,
this is my first post at javaranch and I hope I am posting to the right forum.
Here is the text file:
==================================================================
import java.util.*;
/**
;;
;;Comment 1
*/
code codename1
{
code_contents 1
};
/**
;;
;;Comment 2
*/
code codename2
{
code_contents 2
};
========================================================================
My output should be
==========================================================================
/**
;;
;;Comment 1
*/
/**
;;
;;Comment 2
*/
==========================================================================
I have written my code as shown below, but I am not able to get all the text I need. Need your kind help.
==========================================================
public static void main(
String [] args )
{
try
{
String filename = "C:\\workspace\\xxx\\src\\document.txt";
// Read file into String
FileInputStream fis = new FileInputStream(filename);
int len= fis.available();
byte b[]= new byte[len];
fis.read(b);
String content = new String(b);
//System.out.println(content);
StringBuffer comBuf = new StringBuffer();
StringBuffer ruleBuf = new StringBuffer();
// "/**" == (\/\*\*) - Start
// "*/* == (\*\/)- End
// (\/\*\*)(.*)(\*\/) - Capture the comment block
// == (\\/\\*\\*)(.*)(\\*\\/)
//String commRx = "((\\/\\*\\*)(.*)(\\s*)(\\*\\/))";
String commRx = "((\\/\\*\\*)(\\w)(\\s*)(\\*\\/))";
Pattern commPattern = Pattern.compile(commRx,
(Pattern.MULTILINE));
Matcher commMatcher = commPattern.matcher(content);
ArrayList commArr = new ArrayList();
while( commMatcher.find() )
{
System.out.println(commMatcher.group());
}
}
catch( Exception ex )
{
ex.printStackTrace();
}
}
===================================================================
Thanks in Advance!!!