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

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

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