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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:32:27+00:00 2026-05-22T02:32:27+00:00

Alright, I’ve read the tutorials and scrambled my head too much to be able

  • 0

Alright, I’ve read the tutorials and scrambled my head too much to be able to see clearly now.

I’m trying to capture parameters and their type info from a function signature. So given a signature like this:

function(/*string*/a,b,c)

I want to get the parts like this:

type: string
param:a
param:b
param:c

This is Ok too:

type: string
param:a
type: null (or whitespace)
param:b
type: null (or whitespace)
param:c

So I came up with this regex which is doing the common mistake of repeating the capture (I’ve explicit capture turned on):

function\(((\/\*(?<type>[a-zA-Z]+)\*\/)?(?<param>[0-9a-zA-Z_$]+),?)*\)

Problem is, I can’t correct the mistake. :(. Please help!

  • 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-22T02:32:27+00:00Added an answer on May 22, 2026 at 2:32 am

    Generally, you’d need two steps to get all data.
    First, match/validate the whole function:

    function\((?<parameters>((\/\*[a-zA-Z]+\*\/)?[0-9a-zA-Z_$]+,?)*)\)
    

    Note that now you have a parameters group with all parameters. You can match some of the pattern again to get all matches of parameters, or in this case, split on ,.

    If you’re using .Net, by any chance, you’re in luck. .Net keeps full record of all captures of each group, so you can use the collection:

    match.Groups["param"].Captures
    

    Some notes:

    • If you do want to capture more than one type, you definitely want empty matches, so you can easily combine the matches (though you can sort, but a 1-to-1 capture is neater). In that case, you want the optional group inside your captured group: (?<type>(\/\*[a-zA-Z]+\*\/)?)
    • You don’t have to escape slashes in .Net patterns – / has no special meaning there (C#/.Net doesn’t have regex delimiters).

    Here’s an example of using the captures. Again, the main point is maintaining the relation between type and param: you want to capture empty types, so you don’t lose count.
    Pattern:

    function
    \(
    (?:
        (?:
            /\*(?<type>[a-zA-Z]+)\*/    # type within /* */
            |                           # or
            (?<type>)                   # capture an empty type.
        )
        (?<param>
            [0-9a-zA-Z_$]+
        )
        (?:,|(?=\s*\)))     # mandatory comma, unless before the last ')'
    )*
    \)
    

    Code:

    Match match = Regex.Match(s, pattern, RegexOptions.IgnorePatternWhitespace);
    CaptureCollection types = match.Groups["type"].Captures;
    CaptureCollection parameters = match.Groups["param"].Captures;
    for (int i = 0; i < parameters.Count; i++)
    {
        string parameter = parameters[i].Value;
        string type = types[i].Value;
        if (String.IsNullOrEmpty(type))
            type = "NO TYPE";
        Console.WriteLine("Parameter: {0}, Type: {1}", parameter, type);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright, I'm trying to read a comma delimited file and then put that into
Alright, after doing a ton of research and trying almost every managed CPP Redist
Alright, so I've looked around the web and haven't been able to find what
Alright, I'm trying to use the basic document.getElementsByTagName function, but each time I do,
Alright I am trying to set up an OAuth Provider in PHP, but I
Alright, I am trying to accomplish this: When a user clicks a button that
Alright, I'm trying to figure out why I can't understand how to do this
Alright, so I'm trying to add a slash screen to my app to facilitate
Alright, I'm trying to understand follow sets and I think I got it except
Alright, I'm just trying to learn about using Contact information, but I'm a bit

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.