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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:50:41+00:00 2026-05-15T04:50:41+00:00

I am having this particular requirement where a method has to be identified by

  • 0

I am having this particular requirement where a method has to be identified by different regular expressions for different components. For example, there need to be a regex for return parameter, one for method name, one for argument type and one for argument name. I was able to come up with an expression till this step as follows –

([^,]+) ([^,]+)\((([^,]+) ([^,]+))\)

It works well for a method signature like –

ReturnType foo(Arg parameter)
The regular expression identifies ReturnType, foo, Arg and parameter separately.

Now the problem is that a method can have no/one/multiple arguments separated by commas. I am not able to get a repeating expression for this. Help will be appreciated.

  • 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-15T04:50:41+00:00Added an answer on May 15, 2026 at 4:50 am

    Let’s abstract this out a bit, and say we want to match a (possibly empty) list of digits separated by commas.

    (empty)
    12
    12,34
    12,34,56
    

    The pattern is therefore

    ^$|^\d+(,\d+)*$
    

    Now you can try to replace the components to match what you want:

    • Instead of \d+, whatever regex you use to match type name and identifier
    • Maybe allow \s* around the comma
    • Maybe you’d even add the special varargs last argument (which can also be the first and only)

    Note that if you allow generic type parameters, then you definitely can’t use regex since you can nest the <...> and the language of balanced balanced parentheses of arbitrary depth is not regular.

    Although you can argue that in practice, no one would ever nest type parameters deeper than, say, 3 levels, so then it becomes regular again.

    That said, a proper parser is really the best tool for this. Just look for implementation of Java grammar, say, in ANTLR.


    See also

    • JLS 18.1 The Grammar of the Java Programming Language
    • Java 1.6 Grammar in ANTLR
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a tricky time in thrashing out how best to approach this particular
I'm having a windows form with a tree view control. This tree view has
I am having a dilemma in the logic of this particular issue. Forgive me
Can anybody please help me with this particular query? I'm having ORA-00979 when trying
I am having trouble parsing this particular line using sed: /media/file/1.bmp app:Stuff I want:
This particular example is Get-User and Get-Mailbox (Exchange 2010). Get-User returns some of the
Hi i all having a requirement to delete particular data from a text file.
Having this (simplified) XML: <?xml version=1.0 encoding=UTF-8?> <kml> <Document> <Placemark> <name>Poly 1</name> <Polygon> <coordinates>
Having this errors when trying to compile/run my app using Maven. I've succeeded to
Having this text file : Breathing 1:-29.9396 9:-32.0895 13:-35.6787 2:-36.8527 17:-37.3622 8:-38.0584 14:-38.5265 18:-38.7567

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.