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 ()?
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.