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

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 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