0 votes

For exemple i want to remove everything that is inside parentheses form a string.

var bad_string = "some_text  (text i want to remove) more_text ( remove )"

i would like to to something like this:

var good_string = bad_string.replace("(" + *anything* + ")", "")

the output it should be "sometext moretext"

Thank you in advance !

Godot version v3.3.stable.official
in Engine by (26 points)

1 Answer

+1 vote
Best answer

Simple replacement:

String replace ( String what, String forwhat )

More advanced (regex):

String sub ( String subject, String replacement, bool all=false, int offset=0, int end=-1 )

Regex pattern for everywhing in between parentheses is (might need little tweak based on Godot engine) -> probably dont need 'g' flag which is as 'all' parameter:

by (201 points)
selected by

Thank you, this helped me!

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 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 webmaster@godotengine.org with your username.