Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
REGEX: how to capture terminal flags and arguments?

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!