The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+1 vote


the code editor is not so happy with my regex literal

myRegex.compile("/\d+/g") => Parser Error: Invalid escape sequence

Obviously I can't escape the \ character here.

How can I make him swallow my regex?
(Godot 2.1 Beta)

in Engine by (310 points)

What do you mean "Obviously I can't escape the \ character here"? You actually need to escape, since this is no more than a regular string. Just use "/\\d+/g".

I tried it, but then the regex doesn't work. regex.find(text) then regex.get_captures() # => []. But the text definitely contains numbers and it works for me here That's why I said obvious, because it seems to me to change the entire semantic.

1 Answer

+2 votes
Best answer

For anyone who wonders, it's a really simple fix. Just remove the //g from the expression.

Instead of this


do this

by (310 points)

This is kind of offtopic, but is it possible to get this regex working:


Or do you know if Godot's RegEx system is limited to only the libraries and not the "general" RegEx? (IF that makes sense) :P

the regex for matching bbcode could be


them just use the substitution method :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.