How can i refer to *anything* in a string?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ati97

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 “some_text more_text”

Thank you in advance !

:bust_in_silhouette: Reply From: IceExplosive

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:

/\(.+\)/Ug

Thank you, this helped me!

Ati97 | 2021-07-14 19:32