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

135
Vistas
Create a regex to find queries separated by a semicolon or a space, similar to how GitHub Search works

I'm attempting to create a regex to catch the values of qualifier: value pairs, similar to how it's done in GitHub Search

As an example:

project name: foo/bar, foo/bar; status: online, offline; user: test location: Spain, Italy

A semicolon or space can be used to separate each qualifier:value pair.

Furthermore, each value can have multiple parameters separated by commas:

status: online, offline

The goal is to capture the specific qualifier's concrete value.

My current solution is as follows:

function getMatch(qualifier, string) {
    var formattedStr = string.replace(/ \/ | \/|\/ /g, "/");

    const regex = new RegExp(`${qualifier}:[\\s]?([,/A-Za-z0-9_-]*)[;\\s]?`, "g");
    var match = (formattedStr.match(regex) || []).map((e) =>
        e.replace(regex, "$1")
    );
    console.log(match)
}

However, if the value contains multiple parameters separated by commas, it will only catch the first occurrence:

For status: online, offline it will catch the value online only.

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

0

You're missing a space character in your character class here: [,/A-Za-z0-9_-]

Also, you can make your life a bit better by using a letter wildcard \w instead of the A-Za-z0-9 bit.

Here's my tweaked version: https://regexr.com/6ok61

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