Regex error "undetermined group"

Hi!
I’ve never used regex expressions before so this might be an obvious one, but I’ve been trying to get this regex replace expression to work;

RegEx::Replace(“(^|\b)([a-z])\w{1,3}”, “gi”, “Lorem ipsum dolor sit amet”, “XXX”)

However I keep getting this error;

The regex expression works when i use it in this site; https://regexr.com/ (which is the site i’ve used to try and learn regex and cobble this expression together lol) so im a little confused why it won’t work in gdevelop :stuck_out_tongue:

Thanks in advance!

When I tried testing your expression, I noticed the \ was causing a problem. GD seems to treat them as a special character or something. I checked the forum and someone said that when using \ you need to 2 slashes \\ or a single /

They both worked but gave different results.

https://forum.gdevelop.io/t/using-custom-player-name-in-yarn-dialogue/50689/22

This seems to work. At least, it doesn’t cause an error. IDK if it returns what you expect to.

RegEx::Replace("(^|\\b)([a-z])\\w{1,3}", "gi" , "Lorem ipsum dolor sit amet" , "XXX" )


Top is with \\ bottom /

Screenshot_20240702_025152_Chrome

That works, thanks!
Though you wouldn’t happen to know if there’s a way of wrapping the text found by the regex with bbcode tags somehow? I’m realizing now that this regex method might not work for what I was trying to do (was experimenting with a text accessability option inspired by Bionic Reading), but I don’t really understand the regex extension enough yet to be sure if im barking up the wrong tree or not :sweat_smile:

I’m not all that strong with RegEx or BB Text.

What exactly are you trying to do?

I’m trying to make the first 3 or so letters of each word bolded, basically

Yes. I helped someone with something similar.

I don’t know the exact code or if you need to use 2 RegEx expression or you can reword your expression. You just need to place your text between opening and closing tags.

What logic are you using to decide which letters need to be bold?

I did consider that method, but I hoped I’d be able to do it in a less manual way. The game I’m working on is a text-heavy narrative game so to have to add bbcodes to every single word would simply be too much work.

The logic would be that regex expression, basically to find the first 3 letters of each word in a text. But I guess you can’t inject bbtags around each snippet found by the regex?

It’s not a critical feature so its not a big deal if i can’t make it, honestly I was mainly curious to see if it was a possibility :stuck_out_tongue:

I was currious. With some help from the web and a couple of bots. ChatGPT helped, Clause AI gave me bad advice.

RegEx::Replace("\\b([a-zA-Z]{1,3})", "gi" , "Lorem ipsum dolor sit amet", "[b]$&[/b]" )

You probably don’t need both a-zA-Z with the gi flag. I’m still learning about RegEx

oh my god, that works! :open_mouth: massive thanks :smiley:

1 Like