Match a Regular Expression in Larzscript
Test, extract, and replace with a real (if deliberately small) regex engine - literals, classes, quantifiers, anchors.
regex is a minimal backtracking engine built on native regex_match/find/replace/split primitives - no capture groups or alternation, but real character classes and quantifiers for the validation/cleanup patterns most scripts actually need.
larzscript pkg install regex
Code
import "regex" as regex
print(regex.test("[0-9]+", "order #4821"))
print(regex.matched_text("[0-9]+", "order #4821"))
print(regex.replace("[^a-z0-9]+", "Hello, World!".lower(), "-"))Output
true 4821 hello-world-
Related
larzregexPattern matching - literals, classes, quantifiers, anchors via a small backtracking engine→FizzBuzz in LarzscriptThe classic interview warm-up: print 1 to N, but Fizz for multiples of 3, Buzz for multiples of 5, FizzBuzz for both.→Reverse a String in LarzscriptFlip a string end to end - one of the smallest real string algorithms, and a good first look at the str package.→Check if a String is a Palindrome in LarzscriptDetect whether a string reads the same forwards and backwards, ignoring case, spaces and punctuation.→