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

96
Vistas
Javascript regex flag U in Firefox doesn't work

Given the one-line string (a lot of div tags with name+image inside)

<div id="img-1" class="draggable">AP2<br><img src="URL"></div><div id="img-3" class="draggable">AP6<br><img src="URL"></div><div id="img-6" class="draggable">AP5<br><img src="URL"></div>...

which is produced after User has drag-dropped the pictures, I want to retrieve the actual order from the div.id : "1", "3", "6"...

On https://regex101.com/ I wrote the regex /img-([^()]*)" class/gU which works perfectly: img-1" class + img-3" class + img-6" class are selected. The next step is to obtain 1, 3, 6 with removing img- and " class.

Prob: on FF (Mac) I get the console message Uncaught SyntaxError: invalid regular expression flag U ... so I try another regex /img-([^()]*)" class/g but it doesn't work as expected on regex101: all is selected from first img- to last class : img-1" class="draggable">AP2 ---> </div><div id="img-6" class. Changing flags to /g /gi /gim gives the same result.

But writing <div id="img-1" class="draggable">AP2<br><img src="URL"></div>()<div id="img-3" class="draggable">AP6<br><img src="URL"></div>()<div id="img-6" class="draggable">AP5<br><img src="URL"></div> (with parenthesis between the divs) works.

How to explain it and is there another regex to capture what is expected without adding these ()?

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

0

First, I dont think this is Firefox issue, yes it works on regex101 but because on the left hand side you did not select the right language. Select JS (ECMAscript, it is the superset), and U option will disappear.

U flag is for 'ungreedy', I do not know yet if any JS engines support it, but you can achieve the same effect by:

/img-([^()]*?)" class/g

with just the g flag. ? makes the '*' ungreedy.

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