regex.gd 549 B

123456789101112131415161718192021222324
  1. extends VBoxContainer
  2. # Member variables
  3. var regex = RegEx.new()
  4. func update_expression(text):
  5. regex.compile(text)
  6. update_text()
  7. func update_text():
  8. for child in $List.get_children():
  9. child.queue_free()
  10. if regex.is_valid():
  11. var matches = regex.search($Text.get_text())
  12. if matches != null:
  13. for result in matches.get_strings():
  14. var label = Label.new()
  15. label.text = result
  16. $List.add_child(label)
  17. func _ready():
  18. $Text.set_text("They asked me \"What's going on \\\"in the manor\\\"?\"")
  19. update_expression($Expression.text)