Overview
SIMPLE_REGEX_QUICK provides one-liner regex operations plus built-in validators for common patterns like email, URL, phone, and IP addresses.
For pattern builders and advanced features, use SIMPLE_REGEX directly.
Quick Start
local
rx: SIMPLE_REGEX_QUICK
words: ARRAYED_LIST [STRING]
do
create rx.make
-- Check if pattern matches
if rx.matches ("[a-z]+", "hello") then ...
-- Find first match
if attached rx.find ("\w+", "Hello World") as word then
print (word) -- "Hello"
end
-- Find all matches
words := rx.find_all ("\w+", "Hello World") -- ["Hello", "World"]
-- Replace first match
print (rx.replace ("World", "Eiffel", "Hello World")) -- "Hello Eiffel"
-- Replace all matches
print (rx.replace_all ("\d+", "X", "a1b2c3")) -- "aXbXcX"
-- Split by pattern
words := rx.split ("\s+", "Hello World") -- ["Hello", "World"]
-- Common validators
if rx.is_email ("user@example.com") then ...
if rx.is_url ("https://example.com") then ...
if rx.is_phone ("555-123-4567") then ...
if rx.is_ipv4 ("192.168.1.1") then ...
-- Extract all emails/URLs/numbers from text
emails := rx.extract_emails (document)
urls := rx.extract_urls (document)
numbers := rx.extract_numbers (document)
-- Capture groups
groups := rx.find_groups ("(\w+)@(\w+)", "user@host")
-- ["user", "host"]
end
API Reference
Matching
| Feature | Description |
|---|---|
matches (pattern, text) | Does pattern match anywhere? |
matches_full (pattern, text) | Does pattern match entire text? |
Finding
| Feature | Description |
|---|---|
find (pattern, text) | Find first match |
find_all (pattern, text) | Find all matches |
find_groups (pattern, text) | Get capture groups |
count_matches (pattern, text) | Count matches |
Replacing
| Feature | Description |
|---|---|
replace (pattern, replacement, text) | Replace first match |
replace_all (pattern, replacement, text) | Replace all matches |
Splitting
| Feature | Description |
|---|---|
split (pattern, text) | Split text by pattern |
Common Validators
| Feature | Description |
|---|---|
is_email (text) | Valid email format? |
is_url (text) | Valid URL format? |
is_phone (text) | Valid phone format? |
is_ipv4 (text) | Valid IPv4 address? |
Extractors
| Feature | Description |
|---|---|
extract_emails (text) | Extract all email addresses |
extract_urls (text) | Extract all URLs |
extract_numbers (text) | Extract all numbers |
Utilities
| Feature | Description |
|---|---|
escape (text) | Escape regex special characters |