Menu

How do I get an entire line, like using grep?

Help
2003-05-29
2004-06-08
  • Nobody/Anonymous

    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?

     
    • Nobody/Anonymous

      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

       
    • Nobody/Anonymous

      You might try a pattern like:

      ^.*?(?:regex).*?$

      Compiled with Pattern.MULTILINE (but NOT Pattern.DOTALL).

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.