GDScript Verbal Expressions
A port of VerbalExpressions to GDScript. Tested on Godot 3.4.x.
Based on the Java implementation.
An itch.io demo can be found here.
See the tests
directory for more examples.
Quickstart
- Copy the
addons/verbal-expressions/
folder to your project'saddons
directory (create theaddons
directory if it doesn't exist) - Load the
verbal_expressions.gd
file in your script and create a new instance of it - Start constructing the regex expression
- Call
build()
to compile the expression - Use the usual built-in
ReGex
methods to do regex stuff
Example
Verify a URL
var verbal_expressions = load("res://addons/verbal-expressions/verbal_expressions.gd").new()
verbal_expressions \
.start_of_line() \
.then("http") \
.maybe("s") \
.then("://") \
.maybe("www.") \
.anything_but(" ") \
.end_of_line() \
.build()
var regex_match = verbal_expressions.search("https://godotengine.org/")
assert(regex_match != null)
# Technically unnecessary since `search(...)` returns null if there is no match
assert(regex_match.get_string() == "https://godotengine.org/")