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

  • SEARCH
  • Home
  • 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 6378767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:03:01+00:00 2026-05-25T02:03:01+00:00

I have to recognize some characters in a .c file. For now I have

  • 0

I have to recognize some characters in a .c file. For now I have to recognize the #define line but I would like to exclude the comments after the definition. For example:

#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c)) /* We're doing kernel work */

I have these results :

group1="KERNEL_VERSION"
group2="(a,b,c) ((a)*65536+(b)*256+(c)) /* We're doing kernel work */"

I would like to get rid of /* We're doing kernel work */

I have tried everything I just can’t get rid of it. Here is where I am:

Pattern cdef = Pattern.compile("^#[\\t ]*define[\\t ]+(\\w+)[\\t ]*(.*)",Pattern.DOTALL);

I have tried adding ^[\\/\\*\\w+] or [\\t ]+^\\/+\\*\\w*\\ ….. at the end of the string but either I lose all the second group or it does nothing

thanks a lot,

!!!! EDIT: I would like to find a way to eliminate a C comment so: /* comment */ from a pattern

EDIT 2: The way I see it I think it there should be a way to give the following istruction:
“if you find “/“, don’t take anything else, I am reading the file line by line so whatever is after the / can be thrown away:

This is where I am treating the second group: “….(.)” So I have tried adding ^[\/\] at the end of my string but it doesnt work and I lose the whole second part

  • 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-05-25T02:03:02+00:00Added an answer on May 25, 2026 at 2:03 am

    You almost have it. Just specify the comment at the end of your string. Like this:

    (\\/\\*.*\\*\\/)
    

    Complete test program:

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class TestMain {
        public static void main(String[] args) {
            Pattern cdef = Pattern.compile("^#[\\t ]*define[\\t ]+(\\w+)[\\t ]*(.*)(\\/\\*.*\\*\\/)", Pattern.DOTALL);
            Matcher matcher = cdef
                    .matcher("#define KERNEL_VERSION(a,b,c) ((a)*65536+(b)*256+(c)) /* We're doing kernel work */");
            System.out.println(matcher.matches());
            for (int n = 0; n <= matcher.groupCount(); n++)
                System.out.println(matcher.group(n));
        }
    }
    

    Output:

    true
    #define KERNEL_VERSION(a,b,c) ((a)/65536+(b)/256+(c)) /* We're doing kernel work */
    KERNEL_VERSION
    (a,b,c) ((a)/65536+(b)/256+(c)) 
    /* We're doing kernel work */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code to read the lines from a file, I would like
I have problem with BWToolkit and XCode. For some reasons Xcode not recognize bwtoolkit
tesseract OCR have a command line interface, which allow us to recognize text from
I have a HTML file and it has some information in spanish. I am
I have a file with a syntax that looks like this: ! <Group>, Column1,
I would like to encode strings of varying length (typically 1-100 characters) to integers
I have looked over the Repository pattern and I recognized some ideas that I
I'm looking to have windows recognize that certain folders are associated to my application
I have a project to recognize the footprint of animals. It is similar to
I have to ask this, because: The only thing I recognize is, that if

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.