Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda