Skip to content

Instantly share code, notes, and snippets.

@nathggns
Last active December 18, 2015 05:39
Show Gist options
  • Select an option

  • Save nathggns/5734725 to your computer and use it in GitHub Desktop.

Select an option

Save nathggns/5734725 to your computer and use it in GitHub Desktop.
This can be used to parse command line arguments
/
(?: # start parameter
(?: # start key value section
(?<keys> # start key
(?: # start long key
--[^=\s]+ # long key
) # end long key
|
(?: # start short key
-[^=] # short key
) # end short key
) # end key
(?: # start value
[=\s] # key value seperator
(?<values> # start real value
(?: # start simple values (not inside quotes)
\\. # escaped characters
|
[^\s\-"'] # normal characters
)+ # end simple values
|
(?: # start advances values (inside quotes)
(?<start>["']) # start quote
(?:
\\. # escaped characters
|
(?!\<start>) # any character
. # besides end quote
)*?
\k<start> # end quote
) # end adances
)
)? # end value
) # end key val section
|
(?<others> # start keyless parameter section
(?: # start simple section (not inside quotes)
(?:
\\. # escaped characters
|
[^\s\-"'] # normal characters
)+
) # end simple section
|
(?: # start advanced values (inside quotes)
(?<startkeyless>["']) # start quote
(?:
\\. # escaped character
|
(?!\<startkeyless>) # anything but
. # end quote
)*?
\k<startkeyless> # end quote
) # end advanced values
) # end key less parameter section
) # end parameter
\s? # parameter seperator
/x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment