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 837895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:12:58+00:00 2026-05-15T05:12:58+00:00

I would like to perform checking on the following: VALID LINES; /**/ some code

  • 0

I would like to perform checking on the following:

VALID LINES;
/**/ some code
*/ some code   /** dsfsdkf sd**/

NOT VALID LINES;
/**/ //some code
*/ /***/ //somecode

So basically if there is a line of code outside a comment it is valid, otherwise not.

What would be the best way to tackle this kind of validation?

Note:
For */ I assume that the /* has been opened some lines before.

  • 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-15T05:12:59+00:00Added an answer on May 15, 2026 at 5:12 am

    This should be quite fast I believe.

    import java.io.*;
    
    class Test {
    
        public static void main(String[] args) throws IOException {
            StringBuffer buf = new StringBuffer();
            BufferedReader r = new BufferedReader(new FileReader("src/Test.java"));
    
            final String nl = System.getProperty("line.separator");
            String line;
            while (null != (line = r.readLine()))
                buf.append(line).append(nl);
    
            for (String code : buf.toString().split("(?ms)/\\*.*?\\*/|//[^\\n]*"))
                System.out.println(code);
        }
    }
    

    If you read up a bit on the internals of reg-exps you’ll realize that regular expressions are quite efficient once the underlying automaton has been compiled and minimized (at least for simple regular expressions like the one above). No matter how you implement your algorithm, it would still need to do roughly the same work that the reg-exp engine does in this scenario anyway.

    (If you look at the String.split method, you’ll note that the internal regular expression is compiled into a Pattern once and for all.)

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

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You aren't really giving enough details (specifically, the code showing… May 16, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer The TargetDir variable contains spaces in your case. You need… May 16, 2026 at 5:10 pm
  • Editorial Team
    Editorial Team added an answer A simple [[cls alloc] init] will do the trick. May 16, 2026 at 5:10 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I would like the following code to work, but have no idea as to
I have an NSTextField that I would like to enable as-you-type spell checking. When
I would like to perform a shell command that takes care of cache files
I would like to perform a SELECT query with MySQL. My goal is to
I am looking for a Java library to do some initial spell checking /
I would like to create a new unix command to automatically list the contents
I have git repositories rA and rB, I would like to copy only specific
I'd like to implement a little test to check connectivity to J2EE services over
I'm currently working on a project in which I'd like to define a generic
My Goal: Checking radio button will disable the 'same' column of dropdownlist in a

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.