I have a log file and I would like to use a regular expression to retrieve all lines where a pattern exists. On Unix, if I "grep" on a file for a pattern, it returns all of the lines where that pattern exists. How can I use jregex to get an entire line, without actually comparing against every line in the file?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have a log file and I would like to use a regular expression to retrieve all lines where a pattern exists. On Unix, if I "grep" on a file for a pattern, it returns all of the lines where that pattern exists. How can I use jregex to get an entire line, without actually comparing against every line in the file?
You can just iterate the individual lines and do an:
private String match(String line, Pattern pattern) {
Matcher matcher = pattern.matcher(line);
if (matcher.find()) {
return line;
}
}
[]s Quartz
You might try a pattern like:
^.*?(?:regex).*?$
Compiled with Pattern.MULTILINE (but NOT Pattern.DOTALL).