Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

177
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda