firasdib / Regex101

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

Golang: Regex flags get copied in the wrong way #2270

Closed auribuo closed 2 months ago

auribuo commented 2 months ago

Bug Description

When clicking the copy button next to the regex textfield the regex that gets copied while using the 'Golang' flavor copies the flags in a way not supported by regexp

Reproduction steps

Select any flag and copy any regex.

Expected Outcome

The flag should be set in the following way (example using 'ungreedy'):

`(?U)<regex>`

instead of

`<regex>`U

Stackoverflow post Available flags (Google re2)

Browser

Waterfox G6.0.13 (64-bit)

OS

Windows 11 Pro 23H2

working-name commented 2 months ago

Hello @auribuo,

That's not a bug, the copy function of the input box is just giving you the regex as you would be able to paste in the box to be able to work on it further.

The function you expect is actually the code generator /codegen?language=golang - that's where the regex is put in a code snippet and properly escaped and formatted for that language. But it doesn't do anything else to it - in other words it doesn't guarantee it'll work in golang if you use some feature that only .NET implements for example.

Hope this clears things up.

auribuo commented 2 months ago

Oh ok! Thanks for the heads up!