Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8289471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:30:55+00:00 2026-06-08T12:30:55+00:00

I am trying to write a program to parse Java Garbage Collection logs. I

  • 0

I am trying to write a program to parse Java Garbage Collection logs. I just created a grammar that matches a minor collection. Once I have identified a pattern I would like to parse it into individual tokens. My question is, is there any elegant way to do this with my previously defined grammar?

public class RegexTestHarness {
  private final static String REGEX_SMALL_COLLECTION = "\\d+\\.\\d+: \\[GC \\d+.\\d+: \\[ParNew: \\d+K\\-\\>0K\\(\\d+K\\), \\d+.\\d+ secs\\] \\d+K\\-\\>\\d+K\\(\\d+K\\), \\d+.\\d+ secs\\]";

  public static void main(String[] args){
    Pattern pattern = Pattern.compile(REGEX_SMALL_COLLECTION);           
    Matcher matcher = pattern.matcher("54.770: [GC 54.770: [ParNew: 5232768K->0K(5237824K), 1.1304192 secs] 5238622K->380448K(10480704K), 1.1306410 secs]");
    while (matcher.find()) {            
      System.out.println(matcher.group(0));
      System.out.println(matcher.start());
      System.out.println(matcher.end()); 
    }
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:30:56+00:00Added an answer on June 8, 2026 at 12:30 pm

    You need to add groups to your regex.

    private final static String REGEX_SMALL_COLLECTION = "(\\d+\\.\\d+): \\[GC (\\d+.\\d+): \\[ParNew: \\d+K\\-\\>0K\\(\\d+K\\), \\d+.\\d+ secs\\] \\d+K\\-\\>\\d+K\\(\\d+K\\), \\d+.\\d+ secs\\]";

    and then access the groups to the values. In the above example, I added parenthesis around the first two items you want — this tells the regex engine to capture the matching substrings. You will need to add more. As you are currently doing, you use Matcher.group() to get each group. Note that group 0 is always the entire match. The rest are numbered from 1 up, in order of their opening parens (.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a program in Java that uses osql to generate a
I am trying to write a small java program that will accept a file
I'm trying to write a program that would convert celcius to fahrenheit and visa-versa.
I am trying to write a program that will prompt you to enter someone's
I am trying to write a program that sends basic text files from one
I am trying to write a program that allows a binary to be run,
I am trying to write a program that displays the integers between 1 and
i am trying to write a program that close explorer then runs another program.
I've been trying to write a program in R that implements Newton's method. I've
I am trying to write a script that will parse a directory, find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.