Skip to reading
GDScript Programming & Godot

RegexSearch()

Edition 0.86.4.1 HF1

0.86.4.1 Hotfix 1 edition. Earlier lessons and screenshots retain their original version context; revised references and supplements describe the newer behavior.

Download PDFView PDF page
On this page
Code example
RegexSearch(pattern: String, text: String, all_matches: bool = false) -> Variant

Compile and search a regular expression.

Returns: RegExMatch or null; Array of RegExMatch when all_matches is true.

Code example
RegexSearch("(KEY)-(\\d+)", "KEY-204")

Use get_string/get_start/get_end on the match object. This is different from PCA Script’s dictionary result. Invalid patterns log an error and return null/empty.

ReadTextFile()#

Code example
ReadTextFile(path: String, default_value: String = "") -> String

Read the complete text of an accessible file.

Returns: String or fallback.

Code example
ReadTextFile("user://notes.txt", "")

WriteTextFile()#

Code example
WriteTextFile(path: String, text: String) -> bool

Create/overwrite a text file, creating parent directories as needed.

Returns: Boolean success.

Code example
WriteTextFile("user://notes.txt", "Visited the archive.\n")

This helper accepts user:// only and overwrites. Native FileAccess supports additional modes and platform permissions.

Page 79 of 378Permalink
Go to page