Setting \g in a regular expression
DraGonFiirE opened this issue · 7 comments
Issue type:
- ❓ Question
Question:
Is there a way to set the global regex flag?
also is this accurate?: https://github.com/google/re2/wiki/Syntax
Someone will answer your question soon. In the meantime, you might be able to get help more quickly on our Discord server.
No, setting global regex flags is not possible atm.
You could probably get around with setting flags within groups though?
also is this accurate?: https://github.com/google/re2/wiki/Syntax
Yep, that should be correct!
RE2 is a fast, safe, thread-friendly alternative to backtracking regular expression engines like those used in PCRE, Perl, and Python. It is a C++ library. - Syntax · google/re2 Wiki
Ah sorry, I thought you meant setting regex flags in the global scope, instead of in a group scope.
Not sure why you'd need the g
flag. Could you give an example?
The replace
operator will for instance work in global-mode, so the g
is not needed there.
Ah sorry, I thought you meant setting regex flags in the global scope, instead of in a group scope.
That was my intention at first, I've only posted that picture in respone to:
You could probably get around with setting flags within groups though?
My use case is matching characters like this:
Without the global flag the result would just be that:
And thats exactly the output of the regex_groups
function ingame since its not using the global flag
The code to test with:
{"extra":[{"color":"blue","extra":[{"color":"black","text":"\n x1"},{"color":"gray","text":" | 0▤ +1\n"}],"translate":"block.astralsorcery.spectral_relay"},{"color":"blue","extra":[{"color":"black","text":"\n x4"},{"color":"gray","text":" | 0▤ +4\n"}],"translate":"block.astralsorcery.marble_chiseled"},{"color":"blue","extra":[{"color":"black","text":"\n x4"},{"color":"gray","text":" | 0▤ +4\n"}],"translate":"block.astralsorcery.marble_arch"},{"color":"blue","extra":[{"color":"black","text":"\n x1"},{"color":"gray","text":" | 0▤ +1\n"}],"translate":"block.astralsorcery.black_marble_raw"}],"text":""}
The regex to test with:
translate...\w+.\w+.\w+|x\d
The site I tested with:
https://regex101.com/r/eE6mX3/2