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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:53:50+00:00 2026-06-12T12:53:50+00:00

Developing in .NET 4.0 using C#. (Sorry if this is long-winded…) I want to

  • 0

Developing in .NET 4.0 using C#. (Sorry if this is long-winded…)

I want to create a method such as:

public static string GetCmdLineArgs(
    string cmdLine,
    string pathname )
{
    ...
}

I want to create a Regex pattern that will let let me extract the arguments after the pathname of the executable file. The rules:

  1. The command line may or may not lead off with the pathname.
  2. If the pathname is present, it will be quoted.
  3. The pathname will be an absolute path. As such, it will contain Regex special characters such as “\”, “.”, and possibly others.
  4. If the quoted pathname does not appear at the beginning of the command line, just capture and return the command line, less any leading whitespace.
  5. The pathname may also appear among the arguments. If so, such occurrences should be preserved and returned with the rest of the arguments.
  6. Whitespace characters surrounding the leading pathname should be discarded.
  7. For now, it is sufficient to return all of the arguments in a single string, but capture groups for specific arguments may be added in the future.

I realize that I could hack this function together by using simple System.String operations, but I also want to know how to do it using Regex matching to preserve flexibility for future changes.

Basically, I want to do something like:

// Create the pattern:
//   The pathname is anchored to the beginning of the pattern.
//   The pathname group is non-capturing.
//   Additional capture groups may be added in the future.
string pattern = 
    @"^\s*(?:""" + pathname + """)?\s*(.*)";
Regex regex = new Regex( pattern );
Match = regex.Match( cmdLine );
if ( match.Success )
{
    // extract matching groups...
}

Obviously, the above won’t work as-is because of the presence of Regex special characters in pathname. Is there some way to modify this so it works as I’ve described? Is there a grouping operator that will let me match an unescaped string, or would I have to transform pathname by escaping all possible special characters?

If this has been asked and answered elsewhere, please point me to that post. Thanks!

  • 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-12T12:53:51+00:00Added an answer on June 12, 2026 at 12:53 pm

    See Regex.Escape. I think that’s the only thing you’re missing. Used like

    string pattern = 
        @"^\s*(?:""" + Regex.Escape(pathname) + """)?\s*(.*)";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing an ASP.NET forms webapplication using C#. I have a method which creates
I am developing a web template with ASP.NET using C#. My connection string is:
I'm developing an ASP.NET web app using VS2010,C#, I want to display a file
I'm using VS2010,C# for developing ASP.NET. I want to send periodical messages to server
When developing ASP.NET websites (using VB.NET web forms) - a lot of my time
I am developing a .NET application (using C#) that needs to massage some Adobe
We are developing .net applications and using Clearcase for our SCM needs. We have
What is difference in developing applications using .Net Framework, Asp.net and developing application in
I am developing a website in asp.net using dotnetnuke cms. I need to add
We are currently building the framework for developing a C# .net application using visual

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.