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

144
Views
Regex that only matches when 4 specific words were found

As the title says, I need a Regex to check if a string has this four words (Update, Rollback, Skip, Not Now) and only return them if all of them are present, if not it doesn’t return anything.

Here is an example: {"Update":"iVBORw0KGgo","Rollback":"iVBORw0KGgo","Skip":"iVBORw0KGgo","Not Now":"iVBORw0KGgo"}

In this case, it should return [Update, Rollback, Skip, Not Now]

{"Update":"iVBORw0KGgo","Skip":"iVBORw0KGgo","Not Now":"iVBORw0KGgo"}

In this case, it shouldn’t return any value

I tried to create one by myself but my knowledge of Regex is very basic: (Update|Rollback|Skip|Not Now)

Thanks in advance!


EDIT

I noticed that Regex might not be the best way to achieve this.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

As an alternative to regex, you can use JSON.parse to parse the string into an object and Object.keys to get the properties:

const str = `{"Update":"iVBORw0KGgo","Rollback":"iVBORw0KGgo","Skip":"iVBORw0KGgo","Not Now":"iVBORw0KGgo"}`;

const keys = Object.keys(JSON.parse(str))

const result = keys.sort().toString() == "Not Now,Rollback,Skip,Update" ? keys : "";

console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

While regex is clearly not a good tool for the job, you can do something like this:

re.match("(?=.*Update.*)(?=.*Skip.*)",string)

"(?=WORD)" matches if the expression follows, but doesn't consume any of the string.

Of course, complete the regex by all 4 words that you want similarly.

Also notice that regex by itself doesn't return anything. You need to code for this.

about 4 years ago · Juan Pablo Isaza Report

0

Use this:

^(?=.*"Update"\s*:)(?=.*"Rollback"\s*:)(?=.*"Skip"\s*:)(?=.*"Not Now"\s*:)

(?=...) means that if you lookahead, you find this pattern.

So an empty match will return as soon as we find all these 4 patterns.

demo

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!