RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(?:\s*)(?<=[-|/])(?<name>\w*)[:|=]("((?<value>.*?)(?<!\\)")|(?<value>[\w]*))
Description
Command line named argument parser which allows quoted values and includes &quot;\&quot;&quot; escape for quotes in a quoted value. Non-quoted values can be letter, space or underscore only. Argument names can be letter, space or underscore only. Argument delimiter can be &quot;-&quot; or &quot;/&quot; and name-value separator can be &quot;:&quot; or &quot;=&quot;. All arguments must be named. Spaces are not allowed in
Matches
/a:"value" -big="this -test:1\"23 is & $#@ _ your life" -test=th_3
Non-Matches
this does not match
Author Rating: Not yet rated. Richard Hauer
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Tweaked for parameter w/o value
Name: Isaac
Date: 6/12/2014 3:09:26 PM
Comment:
caveat emptor - I'm new enough with regex that mine are just dangerous! I attempted to alter this regex to allow for parameters that do not have a value, i.e. p1 or /p2. the result: (?:\s*)(?<=[-|/])(?<name>\w*)([:|=]("((?<value>.*?)(?<!\\)")|(?<value>[\w]*)))?


Title: C# produces different results
Name: KRiusd
Date: 8/23/2013 4:32:44 AM
Comment:
I_ve tried this: /switch /path="C:/Program Files" /path2="D:\Program Files" /param="test \"xyz\"" On RegExLib via "Test" everything is fine: path = C:/Program Files path2 = D:\Program Files param = test \"xyz\" But within a C# program I get: path = C path2 = D param = test Any ideas what's going wrong?


Title: C# produces different results
Name: KRiusd
Date: 8/22/2013 10:52:26 AM
Comment:
I_ve tried this: /switch /path="C:/Program Files" /path2="D:\Program Files" /param="test \"xyz\"" On RegExLib via "Test" everything is fine: path = C:/Program Files path2 = D:\Program Files param = test \"xyz\" But within a C# program I get: path = C path2 = D param = test Any ideas what's going wrong?


Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials