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

128
Vistas
JS regex match zero or more optional start with key words

Given string like keydown.capture.once.prevent.shift.control[arrowdown,arrowup]:silent I want to match shift.control[arrowdown,arrowup]:silent

And if the same keydown.capture.once.prevent.shift[arrowdown,arrowup]:silent then it should match shift[arrowdown,arrowup]:silent

Here the keywords shift | control are optional, ex: keydown.capture.once.prevent.[arrowdown,arrowup]:silent, matching string [arrowdown,arrowup]:silen

I wrote the below regex, it can only capture zero or one keyword, but the expected result is zero or all keywords matching into separate group

(shift|control)?\[(.*?)\]:silent, how can we capture all the keywords if they exist?

Additional notes: Order of keywords doesn't matter, ex it can be control.shift[]:silent

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You may use any one of these regex solutions:

(?:(?:shift|control)\.?)*\[([^\]]*)\]:silent

This matches shift or control` optionally followed by a dit and repeats this non-capture group 0 or more times.

RegEx Demo

(?:shift(?:\.control)?|control(?:\.shift)?)?\[([^\]]*)\]:silent

This one matches shift.control OR control.shift in an optional non-capture group with the parts after dot optional in each alternation.

RegEx Demo 2

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could try this:

(?:(shift|control|shift\.control|control\.shift))?(\[.*\]):silent

Test and output: https://regex101.com/r/rMSd2l/1

about 4 years ago · Juan Pablo Isaza Denunciar
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