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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:05:02+00:00 2026-06-17T21:05:02+00:00

I am working on segment of code which needs to be able to recognize

  • 0

I am working on segment of code which needs to be able to recognize no-args constructor declarations in Java source files. While these declarations need to be syntactically correct, they may still be spread across several lines, for example:

public MyCons()

or

public
   MyCons()  

or even

public

   MyCons
  (

    )    

I am very new to regexp in Java, so I am not sure how to get this working. What I have tried so far is this:

public[\\s|\\n]*MyCons[\\s|\\n]*\\(\\S+\\)

It does not seem to detect cases involving multiple alternating whitespaces and newlines though, as in the last example above. Also, it would be great if I could replace MyCons with a regular expression accepting just a word (although this is not strictly necessary).

How could I solve this?

  • 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-17T21:05:03+00:00Added an answer on June 17, 2026 at 9:05 pm

    You need to use backreference since class name and constructor name is always same..

    class\\s*([a-zA-Z\\d$]+).*?(public\\s+\\1\\s*\\(\\s*\\))
    

    Group 2 captures the required constructor

    You need to use DOTALL regex option while matching

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

Sidebar

Related Questions

Need help in following code segment: static void Main(string[] args) { var customers =
The following is a segment from a code which supposes to test communication with
I have a simple section of code which removes an item from an array
I'm working on a visualizer in WPF which has a function to display a
I'm working on a parser in C# to take data from multiple xml files
I have a large segment of code, and it all works, except when there
I am working on a firmware project in which i have to do a
I am working on a program which has a rigid set of 'stages' for
I have pagination on my view which is working fine if i am clicking
I'm working on a project which is using Audio Toolbox for recording and playback

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.