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

0 votes

How do I find the text after the sign "/". For example in the expression:

5 + 10 / 5 - 1

i need to find 5 and replace with float(5) or 5.0. I tried to find the numbers that stand after / ,but it didn't work out for me. Thanks for the help.
it should replace to 5 + 10/ float(5) - 1
my bad code :

var exp1 = "5 + 4/3 * √5"
var regex =
regex.compile(" (i dont know) ")
var result =
var final = exp1
if result != null:
    var rep = "float(%s)" % [result.get_string(1)]
    final = exp1.replace(result.get_string(0), rep)
Godot version 3.2.4
in Engine by (41 points)

1 Answer

+2 votes
Best answer
var exp1 = "5 + 4/3 * √5"
var regex =
print(regex.sub(exp1, "/ float($1)"))

The pattern matches a forward slash followed by any number of whitespaces (including zero), followed by at least one digit. This match is then replaced with the string "/ float($1)", where $1 represents the content of the first subgroup (= the digits).

by (1,732 points)
selected by
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.