firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.2k stars 198 forks source link

Code Generator: JS code doesn't run again on same regex #2300

Open bazsi69 opened 1 week ago

bazsi69 commented 1 week ago

Bug Description

When ran multiple times (e.g. placed in a function) for the same regex string, the generated code doesn't find a match, because the regex.lastIndex is not reset. The generated code should take care of this, e.g. after the "const regex = ..." line, the second line should be regex.lastIndex = 0;

Reproduction steps

run the generated code multiple times

Expected Outcome

for the same regex and str arguments, the code should generate the same results when ran multiple times

Browser

N/A

OS

N/A

working-name commented 1 day ago

Hi @bazsi69

Would you mind updating this fiddle to re-create the issue you describe?

https://jsfiddle.net/bcrn9dz7/