Available
amalgame-regex
POSIX ERE — Test / Match / Replace.
Overview
POSIX extended regular expressions (ERE), through libc's regcomp and regexec. Nothing else to install on Linux and macOS.
Features
- ✓POSIX ERE syntax: classes
[a-z], groups, alternation|, anchors^ $, repetition{n,m} - ✓
Regex.Test(pattern, text): true if the pattern is found - ✓
Regex.Match(pattern, text): first match, with its offsets and groups (GroupText(i)), ornull - ✓
Regex.Replacereplaces the first match,Regex.ReplaceAllall of them
Limits
- –No PCRE: no
\d, no\w, no lookaround, no non-greedy quantifier. Write[0-9]instead of\d. - –
\1is not replaced by the group: the replacement text is copied as is. - –The pattern is compiled again on each call.
- –Windows: MSYS2 only, with the
mingw-w64-x86_64-libsystrepackage; MSVC is not supported.
Example
After amc package add regex, put this code in main.am and run amc run main.am.
import Amalgame.Regex
public class Program {
public static void Main() {
let email: string = "ada@example.org"
if (Regex.Test("^[a-z]+@[a-z]+\\.[a-z]+$", email)) {
Console.WriteLine("valid address")
}
// POSIX: [0-9], not \d
let m = Regex.Match("([0-9]{4})-([0-9]{2})-([0-9]{2})", "on 2026-05-24")
if (m != null) {
Console.WriteLine(m.GetText()) // 2026-05-24
Console.WriteLine(m.GroupText(0)) // 2026
}
let clean: string = Regex.ReplaceAll(" +", "too many spaces", " ")
Console.WriteLine(clean) // too many spaces
}
}
At a glance
- License: Apache-2.0
- Install:
amc package add regex - Source: amalgame-lang/amalgame-regex
- Official index: amalgame-lang/packages-index