Integrated Dynamics

Integrated Dynamics

63M Downloads

Setting \g in a regular expression

DraGonFiirE opened this issue · 7 comments

commented

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

commented

Someone will answer your question soon. In the meantime, you might be able to get help more quickly on our Discord server.

commented

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!

GitHub
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
commented

You could probably get around with setting flags within groups though?

Setting the global flag within a group is not supported it seems
grafik

commented

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.

commented

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:
grafik
Without the global flag the result would just be that:
grafik
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

commented

Could you try with regex_scan instead?

commented

regex_scan worked with integer 0
My error was using index_of_regex and assuming the resulting integer is the index of the group that regex_scan needs
Thanks a lot for your time! :)