I'm trying to do some custom terminal flags and arguments, hoping to learn something new, and I feel something is missing, here is what I tried:
/(?<flag>-{0,2}[., a-z0-9_-]*)(?<=\s*)(?<![-])(?<arguments>[\[\<]\S+)?/gim
Note: it's an ES6 regex.
here are the examples to be tested on:
-d, --devices <command> [ios-type...]
-n --no-run
-m, --mobile
-a, --all
-p, --platforms
--os <os-type>
I'm trying to capture all hyphen starting params as a <flag> group in one match.
While capturing each of the argument in a separate <arguments> group as different matches.
if you would try it in https://regex101.com/ you will notice extra spaces and null matches in both <flag> and <arguments> in which I didn't know how to get rid of.
here are the results:
-d, --devices <command>
-d, --devices
<command>
[ios-type...]
[ios-type...]
-n --no-run
-n --no-run
-m
-m
--mobile
--mobile
-a, --all
-a, --all
-p, --platforms
-p, --platforms
--os <os-type>
--os
<os-type>
if you have any thoughts please let me know.