Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!