virtualx-engine/demos/misc/regex/regex.gd
Rémi Verschelde 8639cecf4c Improve code formatting and update to 2.0
The scripts were streamlined using more or less the following conventions:
 - space after a comma in lists of arguments
 - space around weak operators (+, -), no space around strong operators (*, /)
 - space after a comment start (#)
 - removed trailing spaces or tabs, apart from those that delimit the function indentation level (those could be removed too but since they are added automatically by the editor when typing code, keeping them for now)
 - function blocks separate by two newlines

The scene files were resaved with the (current) 2.0 format, and some scenes that were in XML format were converted to SCN, to be consistent across all demos.
2015-12-09 08:38:23 +01:00

28 lines
590 B
GDScript

extends VBoxContainer
# member variables
var regex = RegEx.new()
func update_expression(text):
regex.compile(text)
update_text()
func update_text():
var text = get_node("Text").get_text()
var list = get_node("List")
for child in list.get_children():
child.queue_free()
if regex.is_valid():
regex.find(text)
for res in regex.get_captures():
var label = Label.new()
label.set_text(res)
list.add_child(label)
func _ready():
get_node("Text").set_text("They asked me \"What's going on \\\"in the manor\\\"?\"")
update_expression(get_node("Expression").get_text())