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

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

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