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

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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